github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/transport/internet/http/config.go (about)

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