github.com/v2fly/v2ray-core/v4@v4.45.2/transport/internet/http/config.go (about)

     1  //go:build !confonly
     2  // +build !confonly
     3  
     4  package http
     5  
     6  import (
     7  	"github.com/v2fly/v2ray-core/v4/common"
     8  	"github.com/v2fly/v2ray-core/v4/common/dice"
     9  	"github.com/v2fly/v2ray-core/v4/transport/internet"
    10  )
    11  
    12  const protocolName = "http"
    13  
    14  func (c *Config) getHosts() []string {
    15  	if len(c.Host) == 0 {
    16  		return []string{"www.example.com"}
    17  	}
    18  	return c.Host
    19  }
    20  
    21  func (c *Config) isValidHost(host string) bool {
    22  	hosts := c.getHosts()
    23  	for _, h := range hosts {
    24  		if h == host {
    25  			return true
    26  		}
    27  	}
    28  	return false
    29  }
    30  
    31  func (c *Config) getRandomHost() string {
    32  	hosts := c.getHosts()
    33  	return hosts[dice.Roll(len(hosts))]
    34  }
    35  
    36  func (c *Config) getNormalizedPath() string {
    37  	if c.Path == "" {
    38  		return "/"
    39  	}
    40  	if c.Path[0] != '/' {
    41  		return "/" + c.Path
    42  	}
    43  	return c.Path
    44  }
    45  
    46  func init() {
    47  	common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
    48  		return new(Config)
    49  	}))
    50  }