After the success handshake of WebSocket, could we used gzip compression?
Here are my tests:
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/
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://tools.ietf.org/html/rfc7692
Yes it could. Chrome 19+ supports it.
"https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_compressed/server_advanced.py"
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.static import File
from autobahn.twisted.websocket import WebSocketServerFactory, \
listenWS
from autobahn.websocket.compress import *
def accept(offers):
for offer in offers:
return PerMessageDeflateOfferAccept(offer)
debug = True
factory = WebSocketServerFactory(u"ws://127.0.0.1:9000", debug=debug, debugCodePaths=debug)
factory.setProtocolOptions(perMessageCompressionAccept=accept)
listenWS(factory)
webdir = File(".")
web = Site(webdir)
reactor.listenTCP(8080, web)
reactor.run()
More info: how PerMessageDeflateOffer is used in Autobahn examples.