try new ws proxy

This commit is contained in:
Bel LaPointe
2026-09-09 07:24:03 -07:00
parent 92d8c334a2
commit 482c1f81f5
4 changed files with 20 additions and 241 deletions
+16 -8
View File
@@ -12,6 +12,7 @@ import (
"strings"
"time"
"github.com/pretty66/websocketproxy"
"github.com/viki-org/dnscache"
)
@@ -95,17 +96,24 @@ func (c Config) serveHTTPProxy(w http.ResponseWriter, r *http.Request, endpoint
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 {
if strings.HasPrefix(u.Scheme, "s") {
u.Scheme = "wss"
wsu := *u
if strings.HasPrefix(wsu.Scheme, "s") {
wsu.Scheme = "wss"
} else {
u.Scheme = "ws"
wsu.Scheme = "ws"
}
if DefaultUpgrader.CheckOrigin == nil {
DefaultUpgrader.CheckOrigin = func(*http.Request) bool {
return true
}
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())
return nil
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
NewProxy(u).ServeHTTP(w, r)
wp.ServeHTTP(w, r)
return
}