原因是Safari的Websocket连接是基于HTTP/1.1的,需要把Websocket Sever的应答也基于HTTP/1.1
一个不合适应答报文示例: 1、Safari请求基于HTTP/1.1建立WebSocket连接 2、Server应答为基于HTTP/1.0,那么Safari将关闭本次WebSocket连接请求
GET / HTTP/1.1 #Safari请求基于HTTP/1.1建立WebSocket连接
Upgrade: websocket
Connection: Upgrade
Host: localhost:8000
Origin: http://localhost:8000
Pragma: no-cache
Cache-Control: no-cache
Sec-WebSocket-Key: psuWu4PKpvC5PlimntI1uw==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: x-webkit-deflate-frame
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15
HTTP/1.0 101 Switching Protocols #Server应答为基于HTTP/1.0,那么Safari将关闭本次WebSocket连接请求
Server: SimpleHTTP/0.6 Python/2.7.15
Date: Wed, 08 Sep 2021 07:26:20 GMT
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: Mwq3JIMwIENZgkjooYLJobX4L90=
|