websocket可以支持gzip压缩吗? [英] Could websocket support gzip compression?
问题描述
在成功完成WebSocket握手之后,我们可以使用gzip压缩吗?
After the success handshake of WebSocket, could we used gzip compression?
这是我的测试:
- 我使用高速公路lib构建服务器,然后以以下方式响应客户端:
HTTP/1.1 101 Switching Protocols content-encoding: gzip Connection: Upgrade Server: AutobahnPython/?.?.? Upgrade: WebSocket Sec-WebSocket-Accept: RIR8KmljoV8Cv9mdiLY7GM2nYMc=
- 然后我的服务器使用gzip压缩
- 然后chrome浏览器得到了结果,但它告诉我无法将文本帧解码为UTF-8"
- I use autobahn lib to build a server, then respon to client as:
HTTP/1.1 101 Switching Protocols content-encoding: gzip Connection: Upgrade Server: AutobahnPython/?.?.? Upgrade: WebSocket Sec-WebSocket-Accept: RIR8KmljoV8Cv9mdiLY7GM2nYMc=
- then my server uses gzip compression
- and the chrome browser got the result, but it told me that "could not decode a text frame as 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屋!