config.go 619 B

123456789101112131415161718192021222324252627282930313233343536
  1. package websocket
  2. import (
  3. "net/http"
  4. "github.com/xtls/xray-core/common"
  5. "github.com/xtls/xray-core/transport/internet"
  6. )
  7. const protocolName = "websocket"
  8. func (c *Config) GetNormalizedPath() string {
  9. path := c.Path
  10. if path == "" {
  11. return "/"
  12. }
  13. if path[0] != '/' {
  14. return "/" + path
  15. }
  16. return path
  17. }
  18. func (c *Config) GetRequestHeader() http.Header {
  19. header := http.Header{}
  20. for k, v := range c.Header {
  21. header.Add(k, v)
  22. }
  23. header.Set("Host", c.Host)
  24. return header
  25. }
  26. func init() {
  27. common.Must(internet.RegisterProtocolConfigCreator(protocolName, func() interface{} {
  28. return new(Config)
  29. }))
  30. }