Reputation: 375
I am creating a WebSocket that works in Chrome Version 47.0.2526.106 (64-bit) but fails on Safari Version 9.0.2 (11601.3.9). The error is Invalid UTF-8 sequence in header value
. It appears that Safari is requiring certain headers to be included and in certain formats but I cannot find which.
I used the open source WebSocketHandshake
line
if (valueStr.isNull()) {
m_context->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "invalid UTF-8 sequence in header value", 0, clientOrigin(), 0);
return 0;
}
The request is as follows:
General
Request URL:wss://example.server.io/query?string=test
Request Method:GET
Status Code:101 Switching Protocols
Response Headers
Connection:Upgrade
Sec-WebSocket-Accept:R3JnbOI454z48aMONLd+8HP6Asg=
Set-Cookie:
Upgrade:websocket
Request Headers
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,fr;q=0.6,fr-CA;q=0.4
Cache-Control:no-cache
Connection:Upgrade
DNT:1
Host:example.server.io
Origin:http://localhost:3000
Pragma:no-cache
Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits
Sec-WebSocket-Key:QUuX6/L23NIezYa4aZJbFw==
Sec-WebSocket-Version:13
Upgrade:websocket
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Query String Parameters
string:test
Upvotes: 4
Views: 4346
Reputation: 4829
Safari/WebKit does not like empty headers. In this particular case, the problem is the empty Set-Cookie:
header. It is a bug in Webkit.
Chrome had that problem too but they fixed it in Blink.
Remove that header in the server response and it should work.
Upvotes: 3