Files
MrAlders0n 695cbbe2aa fix(ws): send Safari and iOS clients uncompressed frames
iOS WebKit drops the socket on the first permessage-deflate message, so every iPhone and iPad browser reconnected about every 0.1 s since 2.1.0. Compress only for Chromium, Firefox and the app.
2026-10-31 16:40:19 -04:00

33 lines
1.9 KiB
Go

// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package ws
import "testing"
func TestCompressesFor(t *testing.T) {
for _, tc := range []struct {
name, userAgent string
want bool
}{
{"iPhone Safari", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 Safari/604.1", false},
{"iPad in desktop mode", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Safari/605.1.15", false},
{"Chrome on iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/141.0.7390.96 Mobile/15E148 Safari/604.1", false},
{"Firefox on iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/144.0 Mobile/15E148 Safari/605.1.15", false},
{"Edge on iOS", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) EdgiOS/141.0.3537.71 Version/26.0 Mobile/15E148 Safari/604.1", false},
{"no User-Agent", "", false},
{"script", "python-requests/2.32.3", false},
{"Chrome", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36", true},
{"Edge", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0", true},
{"Chrome on Android", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Mobile Safari/537.36", true},
{"Firefox", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:144.0) Gecko/20100101 Firefox/144.0", true},
{"BEACON Mobile", "Dart/3.9 (dart:io)", true},
} {
t.Run(tc.name, func(t *testing.T) {
if got := compressesFor(tc.userAgent); got != tc.want {
t.Fatalf("compressesFor = %v, want %v", got, tc.want)
}
})
}
}