Merge pull request #748 from messense/feature/websocket-config
Add websocket max_size and max_queue configuration
This commit is contained in:
commit
21aa3f6578
|
@ -696,7 +696,9 @@ class Sanic:
|
|||
'loop': loop,
|
||||
'register_sys_signals': register_sys_signals,
|
||||
'backlog': backlog,
|
||||
'has_log': has_log
|
||||
'has_log': has_log,
|
||||
'websocket_max_size': self.config.WEBSOCKET_MAX_SIZE,
|
||||
'websocket_max_queue': self.config.WEBSOCKET_MAX_QUEUE
|
||||
}
|
||||
|
||||
# -------------------------------------------- #
|
||||
|
|
|
@ -122,9 +122,11 @@ class Config(dict):
|
|||
▌ ▐ ▀▀▄▄▄▀
|
||||
▀▀▄▄▀
|
||||
"""
|
||||
self.REQUEST_MAX_SIZE = 100000000 # 100 megababies
|
||||
self.REQUEST_MAX_SIZE = 100000000 # 100 megabytes
|
||||
self.REQUEST_TIMEOUT = 60 # 60 seconds
|
||||
self.KEEP_ALIVE = keep_alive
|
||||
self.WEBSOCKET_MAX_SIZE = 2 ** 20 # 1 megabytes
|
||||
self.WEBSOCKET_MAX_QUEUE = 32
|
||||
|
||||
if load_env:
|
||||
self.load_environment_vars()
|
||||
|
|
|
@ -74,7 +74,8 @@ class HttpProtocol(asyncio.Protocol):
|
|||
def __init__(self, *, loop, request_handler, error_handler,
|
||||
signal=Signal(), connections=set(), request_timeout=60,
|
||||
request_max_size=None, request_class=None, has_log=True,
|
||||
keep_alive=True, is_request_stream=False, router=None):
|
||||
keep_alive=True, is_request_stream=False, router=None,
|
||||
**kwargs):
|
||||
self.loop = loop
|
||||
self.transport = None
|
||||
self.request = None
|
||||
|
@ -387,7 +388,8 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
|||
reuse_port=False, loop=None, protocol=HttpProtocol, backlog=100,
|
||||
register_sys_signals=True, run_async=False, connections=None,
|
||||
signal=Signal(), request_class=None, has_log=True, keep_alive=True,
|
||||
is_request_stream=False, router=None):
|
||||
is_request_stream=False, router=None, websocket_max_size=None,
|
||||
websocket_max_queue=None):
|
||||
"""Start asynchronous HTTP Server on an individual process.
|
||||
|
||||
:param host: Address to host on
|
||||
|
@ -442,6 +444,8 @@ def serve(host, port, request_handler, error_handler, before_start=None,
|
|||
keep_alive=keep_alive,
|
||||
is_request_stream=is_request_stream,
|
||||
router=router,
|
||||
websocket_max_size=websocket_max_size,
|
||||
websocket_max_queue=websocket_max_queue
|
||||
)
|
||||
|
||||
server_coroutine = loop.create_server(
|
||||
|
|
|
@ -6,9 +6,12 @@ from websockets import ConnectionClosed # noqa
|
|||
|
||||
|
||||
class WebSocketProtocol(HttpProtocol):
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, *args, websocket_max_size=None,
|
||||
websocket_max_queue=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.websocket = None
|
||||
self.websocket_max_size = websocket_max_size
|
||||
self.websocket_max_queue = websocket_max_queue
|
||||
|
||||
def connection_timeout(self):
|
||||
# timeouts make no sense for websocket routes
|
||||
|
@ -62,6 +65,9 @@ class WebSocketProtocol(HttpProtocol):
|
|||
request.transport.write(rv)
|
||||
|
||||
# hook up the websocket protocol
|
||||
self.websocket = WebSocketCommonProtocol()
|
||||
self.websocket = WebSocketCommonProtocol(
|
||||
max_size=self.websocket_max_size,
|
||||
max_queue=self.websocket_max_queue
|
||||
)
|
||||
self.websocket.connection_made(request.transport)
|
||||
return self.websocket
|
||||
|
|
Loading…
Reference in New Issue
Block a user