ws actually rboke ws

This commit is contained in:
Bel LaPointe
2026-09-09 11:48:34 -07:00
parent a7d613ff8b
commit 052b00caae
-27
View File
@@ -12,7 +12,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/pretty66/websocketproxy"
"github.com/viki-org/dnscache" "github.com/viki-org/dnscache"
) )
@@ -95,32 +94,6 @@ func (c *Config) serveHTTPProxy(w http.ResponseWriter, r *http.Request, endpoint
log.Printf("[%s] %v", c.key(r), err) log.Printf("[%s] %v", c.key(r), err)
} }
isWebsocket := r.Header.Get("Connection") == "Upgrade" || r.Header.Get("Se-Fetch-Mode") == "websocket" || r.Header.Get("Sec-WebSocket-Version") != "" || r.Header.Get("Upgrade") == "websocket"
if isWebsocket {
wsu := *u
if strings.HasPrefix(wsu.Scheme, "s") {
wsu.Scheme = "wss"
} else {
wsu.Scheme = "ws"
}
wp, err := websocketproxy.NewProxy(wsu.String(), func(r2 *http.Request) error {
r2.Header.Set("Cookie", r.Header.Get("Cookie"))
u3 := *u
u3.Path = "/"
r2.Header.Set("Origin", u3.String())
if debug {
log.Printf("r2.Header[Origin] = %q", r2.Header.Get("Origin"))
}
return nil
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
wp.ServeHTTP(w, r)
return
}
var transport http.Transport var transport http.Transport
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
if ip, _ := resolver.FetchOneString(strings.Split(u.Host, ":")[0]); ip != "" { if ip, _ := resolver.FetchOneString(strings.Split(u.Host, ":")[0]); ip != "" {