在成功握手WebSocket之后,我们可以使用gzip压缩吗?
以下是我的测试:
HTTP/1.1 101 Switching Protocols content-encoding: gzip Connection: Upgrade Server: AutobahnPython/?.?.? Upgrade: WebSocket Sec-WebSocket-Accept: RIR8KmljoV8Cv9mdiLY7GM2nYMc=
发布于 2014-11-16 05:02:54
在某些浏览器中,默认情况下会启用WebSocket压缩(在撰写本文时,例如在Chrome中启用,但在Firefox中不启用)。客户端必须为此包含“Sec-WebSocket-Extensions:permessage-deflate”标头。如果服务器使用相同的扩展名进行响应,则WebSocket通信将以帧为单位进行压缩。据我所知,目前还没有浏览器API来启用/禁用扩展。
关于这个主题的一篇好文章是:https://www.igvita.com/2013/11/27/configuring-and-optimizing-websocket-compression/
发布于 2012-07-25 17:53:38
IETF Websocket (HyBi)工作组正在对一个compression extension执行worked on操作。我建议关注他们的邮件列表以获取最新信息。我也推荐你去看看this question。
2017年更新:该扩展现已推出一段时间,请参阅此处:https://www.rfc-editor.org/rfc/rfc7692
发布于 2016-01-21 21:58:48
是的,有可能。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()
更多信息:how PerMessageDeflateOffer is used in Autobahn examples。
https://stackoverflow.com/questions/11646680
复制相似问题