websocket icon indicating copy to clipboard operation
websocket copied to clipboard

Server fails to accept websocket connection with error 400 from iOS Safari

Open smlehbleh opened this issue 5 years ago • 3 comments

When connecting a websocket from iOS safari, the websocket server responds with error 400 and closes the connection (line: 731, websocket.h)

smlehbleh avatar May 27 '20 13:05 smlehbleh

I've done some investigation and it looks like the value for 'User-Agent' key for the websocket request from Safari iOS is longer than the 128 characters specified on line 634: const int ValueBufSize = 128;

Raising this value is one solution, however it's worth noting that the current logic bails out of the entire connection if a value is longer than this. Given that the User-Agent key is not read anyway, it might be best to change the logic from 'break' to 'continue'

smlehbleh avatar May 27 '20 14:05 smlehbleh

problem is at line 658, comment it out and problem goes away for me, it looks like code to fix some buggy client, it causes val_len on line 695 to have -1

` 658 while (val_end[-1] == ' ') val_end--;

695 if (val_len >= ValueBufSize) break; `

this is my connection string

GET / HTTP/1.1 Host: localhost:1234 User-Agent: Mozilla/5.0 (Unix; U; Linux 6.3.5-200.fc38.x86_64) http/2.9.5 Tcl/8.6.12 Connection: keep-alive Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: cZ7A+m2Pl1zuGlE1AcmnDA== Sec-WebSocket-Version: 13 Sec-WebSocket-Protocol: Accept: / Accept-Encoding: gzip,deflate,compress

xvart avatar Jun 07 '23 05:06 xvart

Relaxed some http header validations, please check the latest commit.

MengRao avatar Jul 05 '23 05:07 MengRao