diff --git a/docs/sanic/extensions.md b/docs/sanic/extensions.md index ad9b8156..03feb90c 100644 --- a/docs/sanic/extensions.md +++ b/docs/sanic/extensions.md @@ -1,7 +1,7 @@ # Extensions A list of Sanic extensions created by the community. - +- [Sanic-Plugins-Framework](https://github.com/ashleysommer/sanicpluginsframework): Library for easily creating and using Sanic plugins. - [Sessions](https://github.com/subyraman/sanic_session): Support for sessions. Allows using redis, memcache or an in memory store. - [CORS](https://github.com/ashleysommer/sanic-cors): A port of flask-cors. diff --git a/sanic/server.py b/sanic/server.py index fbe02ff1..049440dd 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -312,7 +312,7 @@ class HttpProtocol(asyncio.Protocol): else: extra['byte'] = -1 - if self.request: + if self.request is not None: extra['host'] = '{0}:{1}'.format(self.request.ip[0], self.request.ip[1]) extra['request'] = '{0} {1}'.format(self.request.method, diff --git a/sanic/websocket.py b/sanic/websocket.py index e8e9922f..37b13f3c 100644 --- a/sanic/websocket.py +++ b/sanic/websocket.py @@ -13,10 +13,18 @@ class WebSocketProtocol(HttpProtocol): 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 + # timeouts make no sense for websocket routes + def request_timeout_callback(self): if self.websocket is None: - super().connection_timeout() + super().request_timeout_callback() + + def response_timeout_callback(self): + if self.websocket is None: + super().response_timeout_callback() + + def keep_alive_timeout_callback(self): + if self.websocket is None: + super().keep_alive_timeout_callback() def connection_lost(self, exc): if self.websocket is not None: diff --git a/sanic/worker.py b/sanic/worker.py index 811c7e5c..a102fb72 100644 --- a/sanic/worker.py +++ b/sanic/worker.py @@ -23,6 +23,9 @@ from sanic.websocket import WebSocketProtocol class GunicornWorker(base.Worker): + http_protocol = HttpProtocol + websocket_protocol = WebSocketProtocol + def __init__(self, *args, **kw): # pragma: no cover super().__init__(*args, **kw) cfg = self.cfg @@ -46,8 +49,9 @@ class GunicornWorker(base.Worker): def run(self): is_debug = self.log.loglevel == logging.DEBUG - protocol = (WebSocketProtocol if self.app.callable.websocket_enabled - else HttpProtocol) + protocol = ( + self.websocket_protocol if self.app.callable.websocket_enabled + else self.http_protocol) self._server_settings = self.app.callable._helper( loop=self.loop, debug=is_debug,