config.go 797 B

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