github.com/imannamdari/v2ray-core/v5@v5.0.5/transport/internet/http/config.go (about)

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