Building42 / Telegraph

Secure Web Server for iOS, tvOS and macOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The header (Sec-WebSocket-Protocol) is not returned to the client on the real device

RockyF opened this issue · comments

v0.18, websocketserver module. client: chrome
It's all right on the emulator, but it's going to go wrong on the real device, getting Sec-WebSocket-Protocol headers empty strings on the client side
error:

WebSocket connection to 'ws://192.168.199.165:9001/asdf' failed: Error during WebSocket handshake: 'Sec-WebSocket-Protocol' header value '' in response does not match any of sent values

request:

Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7
Cache-Control: no-cache
Connection: Upgrade
Host: 192.168.199.165:9001
Origin: http://localhost:63342
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: Nj31L7B8S9YgQmorv/Zi8Q==
Sec-WebSocket-Protocol: sub
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1

response:

Connection: Upgrade
Date: Thu, 01 Nov 2018 06:38:37 GMT
Sec-WebSocket-Accept: N872DmYyQlTZNYZnTzQEzOhWWZs=
Sec-WebSocket-Protocol:
Upgrade: websocket

That is indeed a bug. I've fixed it in the latest commit. You can use the master version if you want to test it out. I'll release a new version (0.19) later today.

The new version will properly verify the protocol in the WebSocket handshake.

Another workaround is to not set a Sec-WebSocket-Protocol (if that is possible).

ok, waiting for 0.19!

Version 0.19 has been released 🎉