This commit is contained in:
David Tan 2017-10-19 19:44:34 -04:00
commit 93e99c2821
4 changed files with 19 additions and 7 deletions

View File

@ -1,7 +1,7 @@
# Extensions # Extensions
A list of Sanic extensions created by the community. 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. - [Sessions](https://github.com/subyraman/sanic_session): Support for sessions.
Allows using redis, memcache or an in memory store. Allows using redis, memcache or an in memory store.
- [CORS](https://github.com/ashleysommer/sanic-cors): A port of flask-cors. - [CORS](https://github.com/ashleysommer/sanic-cors): A port of flask-cors.

View File

@ -312,7 +312,7 @@ class HttpProtocol(asyncio.Protocol):
else: else:
extra['byte'] = -1 extra['byte'] = -1
if self.request: if self.request is not None:
extra['host'] = '{0}:{1}'.format(self.request.ip[0], extra['host'] = '{0}:{1}'.format(self.request.ip[0],
self.request.ip[1]) self.request.ip[1])
extra['request'] = '{0} {1}'.format(self.request.method, extra['request'] = '{0} {1}'.format(self.request.method,

View File

@ -13,10 +13,18 @@ class WebSocketProtocol(HttpProtocol):
self.websocket_max_size = websocket_max_size self.websocket_max_size = websocket_max_size
self.websocket_max_queue = websocket_max_queue 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: 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): def connection_lost(self, exc):
if self.websocket is not None: if self.websocket is not None:

View File

@ -23,6 +23,9 @@ from sanic.websocket import WebSocketProtocol
class GunicornWorker(base.Worker): class GunicornWorker(base.Worker):
http_protocol = HttpProtocol
websocket_protocol = WebSocketProtocol
def __init__(self, *args, **kw): # pragma: no cover def __init__(self, *args, **kw): # pragma: no cover
super().__init__(*args, **kw) super().__init__(*args, **kw)
cfg = self.cfg cfg = self.cfg
@ -46,8 +49,9 @@ class GunicornWorker(base.Worker):
def run(self): def run(self):
is_debug = self.log.loglevel == logging.DEBUG is_debug = self.log.loglevel == logging.DEBUG
protocol = (WebSocketProtocol if self.app.callable.websocket_enabled protocol = (
else HttpProtocol) self.websocket_protocol if self.app.callable.websocket_enabled
else self.http_protocol)
self._server_settings = self.app.callable._helper( self._server_settings = self.app.callable._helper(
loop=self.loop, loop=self.loop,
debug=is_debug, debug=is_debug,