From 3af26540ecce99779aa054ec986c0842fa9329d5 Mon Sep 17 00:00:00 2001 From: Jing Su Date: Mon, 13 Mar 2017 13:28:35 +0800 Subject: [PATCH 1/3] add websocket scheme in request --- sanic/request.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sanic/request.py b/sanic/request.py index 68743c79..c8f14ca0 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -142,6 +142,10 @@ class Request(dict): @property def scheme(self): + if self.app.websocket_enabled \ + and self.headers.get('upgrade') == 'websocket': + return 'ws' + if self.transport.get_extra_info('sslcontext'): return 'https' From 250bb7e29d0f2ae66a9655f79601864f7c111428 Mon Sep 17 00:00:00 2001 From: Jing Su Date: Mon, 13 Mar 2017 18:34:43 +0800 Subject: [PATCH 2/3] add websocket secure scheme in request @messense --- sanic/request.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index c8f14ca0..dc2fd872 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -144,12 +144,14 @@ class Request(dict): def scheme(self): if self.app.websocket_enabled \ and self.headers.get('upgrade') == 'websocket': - return 'ws' + scheme = 'ws' + else: + scheme = 'http' if self.transport.get_extra_info('sslcontext'): - return 'https' + scheme += 's' - return 'http' + return scheme @property def host(self): From ba41ab8f67e484b8ea5bda2dd91603aba1dcec93 Mon Sep 17 00:00:00 2001 From: Jing Su Date: Mon, 13 Mar 2017 18:36:22 +0800 Subject: [PATCH 3/3] fix typo --- docs/sanic/blueprints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sanic/blueprints.md b/docs/sanic/blueprints.md index d1338023..4b704422 100644 --- a/docs/sanic/blueprints.md +++ b/docs/sanic/blueprints.md @@ -57,7 +57,7 @@ Blueprints have much the same functionality as an application instance. ### WebSocket routes -WebSocket handlers can be registered on a blueprint using the `@bp.route` +WebSocket handlers can be registered on a blueprint using the `@bp.websocket` decorator or `bp.add_websocket_route` method. ### Middleware