diff --git a/eventlet/websocket.py b/eventlet/websocket.py index 9321956..1fdb3bf 100644 --- a/eventlet/websocket.py +++ b/eventlet/websocket.py @@ -135,7 +135,12 @@ class WebSocketWSGI(object): return wsgi.ALREADY_HANDLED def _handle_legacy_request(self, environ): - sock = environ['eventlet.input'].get_socket() + if 'eventlet.input' in environ: + sock = environ['eventlet.input'].get_socket() + elif 'gunicorn.socket' in environ: + sock = environ['gunicorn.socket'] + else: + raise Exception('No eventlet.input or gunicorn.socket present in environ.') if 'HTTP_SEC_WEBSOCKET_KEY1' in environ: self.protocol_version = 76 @@ -192,7 +197,13 @@ class WebSocketWSGI(object): return WebSocket(sock, environ, self.protocol_version) def _handle_hybi_request(self, environ): - sock = environ['eventlet.input'].get_socket() + if 'eventlet.input' in environ: + sock = environ['eventlet.input'].get_socket() + elif 'gunicorn.socket' in environ: + sock = environ['gunicorn.socket'] + else: + raise Exception('No eventlet.input or gunicorn.socket present in environ.') + hybi_version = environ['HTTP_SEC_WEBSOCKET_VERSION'] if hybi_version not in ('8', '13', ): raise BadRequest(status='426 Upgrade Required', diff --git a/tests/manual/websocket-gunicorn.py b/tests/manual/websocket-gunicorn.py new file mode 100644 index 0000000..88b823a --- /dev/null +++ b/tests/manual/websocket-gunicorn.py @@ -0,0 +1,48 @@ +import eventlet.websocket +import gunicorn +import os +import random +import sys + + +@eventlet.websocket.WebSocketWSGI +def wsapp(ws): + ws.send(b'test pass') + ws.close() + + +def app(environ, start_response): + body = b''' +