config.go 813 B

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