From 47abf839607709dc594494bddf2ec63ab7233e6e Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Tue, 27 Jun 2017 16:08:35 +0900 Subject: [PATCH 1/5] Protocol configurable gunicorn worker --- sanic/worker.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sanic/worker.py b/sanic/worker.py index 7c02053c..9ca9de90 100644 --- a/sanic/worker.py +++ b/sanic/worker.py @@ -22,6 +22,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 @@ -45,8 +48,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, @@ -136,8 +140,7 @@ class GunicornWorker(base.Worker): if self.max_requests and req_count > self.max_requests: self.alive = False self.log.info( - "Max requests exceeded, shutting down: %s", self - ) + "Max requests exceeded, shutting down: %s", self) elif pid == os.getpid() and self.ppid != os.getppid(): self.alive = False self.log.info("Parent changed, shutting down: %s", self) From 4578f6016b04a6e850bfe6076f12dd3757164e96 Mon Sep 17 00:00:00 2001 From: lanf0n Date: Fri, 13 Oct 2017 16:48:02 +0800 Subject: [PATCH 2/5] to fix condition error that used in `log_response` `request` class is derived from `dict`, so it will never be `True`. --- sanic/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/server.py b/sanic/server.py index 8f60a864..2d47dc4f 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -311,7 +311,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, From ea5b07f636451822cbe923a75e6275118f594006 Mon Sep 17 00:00:00 2001 From: Ashley Sommer Date: Mon, 16 Oct 2017 11:05:01 +1000 Subject: [PATCH 3/5] Update websocket protocol to accomodate changes in HTTP protocol from https://github.com/channelcat/sanic/pull/939 Fixes https://github.com/channelcat/sanic/issues/969 --- sanic/websocket.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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: From 49f3ba39f94c6ef7a6a4cdf0da6459e2cc5b4d3e Mon Sep 17 00:00:00 2001 From: Ashley Sommer Date: Wed, 18 Oct 2017 17:52:03 +1000 Subject: [PATCH 4/5] Add Sanic-Plugins-Framework library to Extensions doc I made a new tool for devs to use for easily and quickly creating Sanic Plugins (extensions), and for application builders to easily use those plugins in their app. --- docs/sanic/extensions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From 5bcbc5a33755c872feb1c3e5eb0c9589590a4d9f Mon Sep 17 00:00:00 2001 From: davidtgq Date: Thu, 19 Oct 2017 19:43:07 -0400 Subject: [PATCH 5/5] Replaced COMMON_STATUS_CODES with a simple 200 check for more fast (#982) * Replaced COMMON_STATUS_CODES with a simple 200 check for more fast * Added IPware algorithm * Remove HTTP prefix from Django-style headers Remove right_most_proxy because it's outside spec * Remove obvious docstrings * Revert "Replaced COMMON_STATUS_CODES with a simple 200 check for more fast" This reverts commit 15b6980 * Revert "Added IPware algorithm" This reverts commit bdf66cb WTF HOW DO I GIT * Revert "Revert "Replaced COMMON_STATUS_CODES with a simple 200 check for more fast"" This reverts commit d8df095 * Revert "Added IPware algorithm" This reverts commit bdf66cb * Delete ip.py --- sanic/exceptions.py | 5 ++--- sanic/response.py | 26 +++++++++----------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/sanic/exceptions.py b/sanic/exceptions.py index e2d808f7..aa1e0d4d 100644 --- a/sanic/exceptions.py +++ b/sanic/exceptions.py @@ -1,4 +1,4 @@ -from sanic.response import ALL_STATUS_CODES, COMMON_STATUS_CODES +from sanic.response import STATUS_CODES TRACEBACK_STYLE = '''