4
4
"context"
5
5
"encoding/json"
6
6
"net/http"
7
+ "strings"
7
8
"time"
8
9
9
10
"github.com/koenbollen/logging"
@@ -18,11 +19,6 @@ import (
18
19
const MaxConnectionTime = 1 * time .Hour
19
20
20
21
func Handler (ctx context.Context , store stores.Store , cloudflare * cloudflare.CredentialsClient ) http.HandlerFunc {
21
- acceptOptions := & websocket.AcceptOptions {
22
- // Allow any origin/game to connect.
23
- InsecureSkipVerify : true ,
24
- }
25
-
26
22
manager := & TimeoutManager {}
27
23
go manager .Run (ctx )
28
24
@@ -34,6 +30,17 @@ func Handler(ctx context.Context, store stores.Store, cloudflare *cloudflare.Cre
34
30
ctx , cancel := context .WithTimeout (ctx , MaxConnectionTime )
35
31
defer cancel ()
36
32
33
+ userAgentLower := strings .ToLower (r .Header .Get ("User-Agent" ))
34
+ isSafari := strings .Contains (userAgentLower , "safari" ) && ! strings .Contains (userAgentLower , "chrome" ) && ! strings .Contains (userAgentLower , "android" )
35
+ acceptOptions := & websocket.AcceptOptions {
36
+ // Allow any origin/game to connect.
37
+ InsecureSkipVerify : true ,
38
+ }
39
+
40
+ if isSafari {
41
+ acceptOptions .CompressionMode = websocket .CompressionDisabled
42
+ }
43
+
37
44
conn , err := websocket .Accept (w , r , acceptOptions )
38
45
if err != nil {
39
46
util .ErrorAndAbort (w , r , http .StatusBadRequest , "" , err )
0 commit comments