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