github.com/xtls/xray-core@v1.8.12-0.20240518155711-3168d27b0bdb/transport/internet/websocket/config.go (about)

     1  package websocket
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/xtls/xray-core/common"
     7  	"github.com/xtls/xray-core/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  }