⚡️ Enable Deflate for web socket connections (#4322)
This commit is contained in:
1 parent
cfd36beaa1
commit
2ae28e1bd3
2 files changed
+13
No files matched your search
@@ -340,6 +340,7 @@ class Server(object):
|
||||
# monkey patch/fix some stuff
|
||||
util.tornado.fix_json_encode()
|
||||
util.tornado.fix_websocket_check_origin()
|
||||
util.tornado.enable_per_message_deflate_extension()
|
||||
util.flask.fix_flask_jsonify()
|
||||
util.watchdog.fix_scandir()
|
||||
|
||||
|
||||
@@ -54,6 +54,18 @@ def fix_json_encode():
|
||||
tornado.escape.json_encode = fixed_json_encode
|
||||
|
||||
|
||||
def enable_per_message_deflate_extension():
|
||||
"""
|
||||
This configures tornado.websocket.WebSocketHandler.get_compression_options to support the permessage-deflate extension
|
||||
to the websocket protocol, minimizing data bandwidth if clients support the extension as well
|
||||
"""
|
||||
|
||||
def get_compression_options(self):
|
||||
return {"compression_level": 1, "mem_level": 1}
|
||||
|
||||
tornado.websocket.WebSocketHandler.get_compression_options = get_compression_options
|
||||
|
||||
|
||||
def fix_websocket_check_origin():
|
||||
"""
|
||||
This fixes tornado.websocket.WebSocketHandler.check_origin to do the same origin check against the Host
|
||||
|
||||
Reference in new issue
Block a user