JavaScript chrome 中 websoet handshake header 中为啥没有 cookie

davidqhr · 2013年04月15日 · 最后由 hawkdeb6072 回复于 2026年09月16日 · 3798 次阅读

疑问如题

chrome 版本是 26.0.1410.65 firefox 中没有这个问题。

chrome 下

GET ws://localhost:4567/games/matching-game/1 HTTP/1.1
Pragma: no-cache
Origin: http://localhost:4567
Host: localhost:4567
Sec-WebSocket-Key: 9NJMQbfnt2FSN2b2MkQ9cQ==
Upgrade: websocket
Sec-WebSocket-Extensions: x-webkit-deflate-frame
Cache-Control: no-cache
Connection: Upgrade
Sec-WebSocket-Version: 13

firefox 下

GET /games/matching-game/1 HTTP/1.1
Host: localhost:4567
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:19.0) Gecko/20100101 Firefox/19.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: http://localhost:4567
Sec-WebSocket-Key: iTKGrDte+JmWeHmpHnFCpQ==
Cookie: rack.session=BAh7CUkiD3Nlc3Npb25faWQGOgZFRiJFODNiOTA0NmJmZDcwNDM0NjVlYjNl%0AMGU3YThiNjU1OGM1ODkxZmYwYWVjOGFhNDUwOGVlN2QxMTdjOGRlMDEzMEki%0ADXRyYWNraW5nBjsARnsISSIUSFRUUF9VU0VSX0FHRU5UBjsARiItNTA1OTFk%0AZWE0YTk3MGM2ZGM2ODhhNzEzZTFlNWUyZWRlMzEzYzA3NUkiGUhUVFBfQUND%0ARVBUX0VOQ09ESU5HBjsARiItYTBiZmM4NzZkNjhmZTdhZWE3MDBkYTVlYTg5%0AMjVhYmFjNmYyZjc5NEkiGUhUVFBfQUNDRVBUX0xBTkdVQUdFBjsARiItNTBj%0AYTM5YWY5NDU1ZTM1NmY2ZTlkOTRjZjU4NzE4ZTQzNzdhZjI5NEkiCWNzcmYG%0AOwBGIkU1Yzk1ZTQ5NTlhN2YwNjVhZDE2YTA1ZWYyMjFkMWY0ODNjMzc1Yzlh%0ANWQxZDQ4NmFhMThhYmRjYjA5ZDE1OTRlSSIMdXNlcl9pZAY7AEZpBg%3D%3D%0A--8122297af5825b47cfae2bf8f30342551dfba2a4
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
GET ws://localhost:4567/games/matching-game/1 HTTP/1.1
Pragma: no-cache
Origin: http://localhost:4567
Host: localhost:4567
Sec-WebSocket-Key: 9NJMQbfnt2FSN2b2MkQ9cQ==
Upgrade: websocket
Sec-WebSocket-Extensions: x-webkit-deflate-frame
Cache-Control: no-cache
Connection: Upgrade
Sec-WebSocket-Version: 13

The difference between Chrome and Firefox here is really interesting, especially since the WebSocket handshake looks almost identical apart from the missing Cookie header in Chrome. Since the same localhost connection works in Firefox, it makes sense to look at how Chrome was handling the session cookie for WebSocket requests at the time. It’s one of those small browser differences that can be surprisingly frustrating when debugging, much like tracking down unexpected behavior in https://gachanebulaapkmod.com/.

需要 登录 后方可回复, 如果你还没有账号请 注册新账号