websocket 可以支持 gzip 压缩吗? [英] Could websocket support gzip compression?
问题描述
WebSocket握手成功后,可以使用gzip压缩吗?
After the success handshake of WebSocket, could we used gzip compression?
这是我的测试:
- 我使用 autobahn lib 构建服务器,然后响应客户端为:
HTTP/1.1 101 交换协议内容编码:gzip 连接:升级服务器:AutobahnPython/?.?.?升级:WebSocket Sec-WebSocket-Accept:RIR8KmljoV8Cv9mdiLY7GM2nYMc=
- 然后我的服务器使用 gzip 压缩
- Chrome 浏览器得到了结果,但它告诉我无法将文本框架解码为 UTF-8"
推荐答案
WebSocket 压缩在某些浏览器中默认启用(在撰写本文时,例如在 Chrome 中,但在 Firefox 中未启用).客户端必须为此包含Sec-WebSocket-Extensions: permessage-deflate"标头.如果服务器以相同的扩展名响应,则 WebSocket 通信以帧为基础进行压缩.据我所知,没有浏览器 API 来启用/禁用扩展.
WebSocket compression is enabled in some browsers by default (at the time of writing for example in Chrome, but not in Firefox). The client has to include the 'Sec-WebSocket-Extensions: permessage-deflate' header for this. If the server responds with the same extension, the WebSocket communication is compressed on a frame basis. As far as I know, there is no browser API to enable/disable extensions.
关于该主题的一篇好文章是:https://www.igvita.com/2013/11/27/configuring-and-optimizing-websocket-compression/
A good article about the topic is: https://www.igvita.com/2013/11/27/configuring-and-optimizing-websocket-compression/
这篇关于websocket 可以支持 gzip 压缩吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!