mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
Add separate host config for websocket
This commit is contained in:
parent
e2302b421c
commit
7e3a8d3a04
3 changed files with 19 additions and 6 deletions
|
@ -25,6 +25,7 @@ func (c *Config) GetRequestHeader() http.Header {
|
|||
for k, v := range c.Header {
|
||||
header.Add(k, v)
|
||||
}
|
||||
header.Set("Host", c.Host)
|
||||
return header
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
)
|
||||
|
||||
type requestHandler struct {
|
||||
host string
|
||||
path string
|
||||
ln *Listener
|
||||
}
|
||||
|
@ -37,6 +38,10 @@ var upgrader = &websocket.Upgrader{
|
|||
}
|
||||
|
||||
func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||
if len(h.host) > 0 && request.Host != h.host {
|
||||
writer.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if request.URL.Path != h.path {
|
||||
writer.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
|
@ -125,6 +130,7 @@ func ListenWS(ctx context.Context, address net.Address, port net.Port, streamSet
|
|||
|
||||
l.server = http.Server{
|
||||
Handler: &requestHandler{
|
||||
host: wsSettings.Host,
|
||||
path: wsSettings.GetNormalizedPath(),
|
||||
ln: l,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue