summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYAMADA Hideki <yamada.hideki@po.ntts.co.jp>2014-05-14 19:11:01 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-05-16 05:03:11 +0900
commit7b6f6388741111482aad8d27c39480ac683685e1 (patch)
treed7ede6c4000d2112ffa143b98aafaa97ebcefa84
parent28339dd774572d3fdd48904438551c8d70ae6cf3 (diff)
wsgi: Support WebSocket
- Hack webob.dec.wsgify for taking start_response function. - Add websocket handshake helper method to controller. Signed-off-by: YAMADA Hideki <yamada.hideki@po.ntts.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/app/wsgi.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/ryu/app/wsgi.py b/ryu/app/wsgi.py
index 384c32c2..320f6b77 100644
--- a/ryu/app/wsgi.py
+++ b/ryu/app/wsgi.py
@@ -67,6 +67,16 @@ class ControllerBase(object):
return getattr(self, action)(req, **kwargs)
+ def websocket_handshake(self, req, handler):
+ ws_wsgi = hub.WebSocketWSGI(handler)
+ return ws_wsgi(req.environ, req.start_response)
+
+
+class wsgify_hack(webob.dec.wsgify):
+ def __call__(self, environ, start_response):
+ self.kwargs['start_response'] = start_response
+ return super(wsgify_hack, self).__call__(environ, start_response)
+
class WSGIApplication(object):
def __init__(self, **config):
@@ -92,13 +102,14 @@ class WSGIApplication(object):
match = self.mapper.match(req.path_info)
return match
- @webob.dec.wsgify
- def __call__(self, req):
+ @wsgify_hack
+ def __call__(self, req, start_response):
match = self._match(req)
if not match:
return webob.exc.HTTPNotFound()
+ req.start_response = start_response
req.urlvars = match
link = URLGenerator(self.mapper, req.environ)