Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could websocket support gzip compression?

Tags:

websocket

gzip

After the success handshake of WebSocket, could we used gzip compression?

Here are my tests:

  1. 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=
  2. then my server uses gzip compression
  3. and the chrome browser got the result, but it told me that "could not decode a text frame as UTF-8"
like image 950
littlesun Avatar asked Sep 03 '25 13:09

littlesun


2 Answers

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.

A good article about the topic is: https://www.igvita.com/2013/11/27/configuring-and-optimizing-websocket-compression/

like image 86
Joel Avatar answered Sep 05 '25 17:09

Joel


There is a compression extension being worked on by the IETF Websocket (HyBi) working group. I would suggest following their mailing list for up-to-date information. I also recommend checking out this question.


Update 2017: The extension has now been available for some time, see here: https://www.rfc-editor.org/rfc/rfc7692

like image 33
Dreen Avatar answered Sep 05 '25 16:09

Dreen