config.go 824 B

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