config.go 653 B

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