[英]Jetty 9.4.26 - gzip compression for websocket byte messages
[英]Could websocket support gzip compression?
在WebSocket成功握手之后,我們可以使用gzip壓縮嗎?
這是我的測試:
HTTP/1.1 101 Switching Protocols content-encoding: gzip Connection: Upgrade Server: AutobahnPython/?.?.? Upgrade: WebSocket Sec-WebSocket-Accept: RIR8KmljoV8Cv9mdiLY7GM2nYMc=
默認情況下,在某些瀏覽器中啟用了WebSocket壓縮(例如在Chrome中編寫,但在Firefox中沒有)。 客戶端必須包含'Sec-WebSocket-Extensions:permessage-deflate'標題。 如果服務器以相同的擴展名響應,則WebSocket通信將以幀為基礎進行壓縮。 據我所知,沒有瀏覽器API來啟用/禁用擴展。
關於該主題的一篇好文章是: https : //www.igvita.com/2013/11/27/configuring-and-optimizing-websocket-compression/
是的,它可以。 Chrome 19+支持它。
"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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.