config.go 893 B

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