diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-10-04 01:16:28 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-10-04 01:17:35 +0200 |
commit | 9dc3dd02f397f83941fbcc7d5271a33857cb5df3 (patch) | |
tree | a3ca788d682f04dee87ecf08b45999614db4ae9e /xP | |
parent | a7c3ed7cc1848305bcb1a799183f657848944397 (diff) | |
download | xK-9dc3dd02f397f83941fbcc7d5271a33857cb5df3.tar.gz xK-9dc3dd02f397f83941fbcc7d5271a33857cb5df3.tar.xz xK-9dc3dd02f397f83941fbcc7d5271a33857cb5df3.zip |
xP: disable WebSocket compression on Safari
Wildly known to be broken.
Diffstat (limited to 'xP')
-rw-r--r-- | xP/xP.go | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -16,6 +16,7 @@ import ( "net" "net/http" "os" + "strings" "time" "nhooyr.io/websocket" @@ -159,13 +160,21 @@ func clientWriteError(ctx context.Context, ws *websocket.Conn, err error) bool { } func handleWS(w http.ResponseWriter, r *http.Request) { - ws, err := websocket.Accept(w, r, &websocket.AcceptOptions{ + opts := &websocket.AcceptOptions{ InsecureSkipVerify: true, - // Note that Safari can be broken with compression. - CompressionMode: websocket.CompressionContextTakeover, + CompressionMode: websocket.CompressionContextTakeover, // This is for the payload; set higher to avoid overhead. CompressionThreshold: 64 << 10, - }) + } + + // AppleWebKit can be broken with compression. + if agent := r.UserAgent(); strings.Contains(agent, " Version/") && + (strings.HasPrefix(agent, "Mozilla/5.0 (Macintosh; ") || + strings.HasPrefix(agent, "Mozilla/5.0 (iPhone; ")) { + opts.CompressionMode = websocket.CompressionDisabled + } + + ws, err := websocket.Accept(w, r, opts) if err != nil { log.Println("Client rejected: " + err.Error()) return |