jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
897 stars 222 forks source link

doesn't work with autobahn client #14

Open luogni opened 10 years ago

luogni commented 10 years ago

Hi i've tried using django-websocket-redis with a python client based on autobahn. I get this error on "./manage.py runserver": Other Exception: Traceback (most recent call last): File "/home/luogni/.virtualenvs/fyc/src/django-websocket-redis/ws4redis/wsgi_server.py", line 78, in call message = websocket.receive() File "/home/luogni/.virtualenvs/fyc/src/django-websocket-redis/ws4redis/websocket.py", line 208, in receive raise e error: [Errno 104] Connection reset by peer Traceback (most recent call last): File "/usr/lib/python2.7/wsgiref/handlers.py", line 86, in run self.finish_response() File "/usr/lib/python2.7/wsgiref/handlers.py", line 127, in finish_response self.write(data) File "/usr/lib/python2.7/wsgiref/handlers.py", line 215, in write self._write(data) File "/usr/lib/python2.7/socket.py", line 324, in write self.flush() File "/usr/lib/python2.7/socket.py", line 303, in flush self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 32] Broken pipe

The error is clear if we look at autobahn log: 2014-03-15 12:04:11+0100 [EchoClientProtocol,client] received HTTP status line in opening handshake : HTTP/1.0 101 Switching Protocols 2014-03-15 12:04:11+0100 [EchoClientProtocol,client] received HTTP headers in opening handshake : {u'content-length': u'0', u'upgrade': u'websocket', u'sec-websocket-accept': u'SBYEiAu41QkehGQrEfRmFxPpPXM=', u'sec-websocket-version': u'13', u'server': u'WSGIServer/0.1 Python/2.7.3', u'connection': u'Upgrade', u'date': u'Sat, 15 Mar 2014 11:04:11 GMT'} 2014-03-15 12:04:11+0100 [EchoClientProtocol,client] failing WebSocket opening handshake ('Unsupported HTTP version ('HTTP/1.0')')

It seems autobahn does a HTTP/1.1 request and django replies with a HTTP/1.0 switching protocol reply. Autobahn doesn't like it nd close the connection. I don't know if this is a django/ws4redis/autobahn/mysetting bug so please forgive me if i filed it on the wrong project! I've tried to remove the HTTP/1.1 check on autobahn and everything works fine but looking at google it seems websocket upgrade header requires http1.1.

willir commented 9 years ago

I get same error with QWebSocket http://doc.qt.io/qt-5/qwebsocket.html

samunda commented 9 years ago

Yes, the issue of ws4redis sending HTTP/1.0 is still there. RFC for websocket (https://tools.ietf.org/html/rfc6455) only mentions HTTP/1.1

gabn88 commented 9 years ago

With Django 1.7 I also experience this issue. Is there a way to patch this?

jrief commented 9 years ago

I never worked with the Autobahn client and I have no intention to do so soon, because currently I have no need for it. Whenever you want to add this feature, please go ahead.

darkpixel commented 9 years ago

I'm running in to this on all the .NET websocket clients. They complain about HTTP/1.0 and also that the content-length header is 0 bytes when the server sends data.

darkpixel commented 8 years ago

This also seems to affect lots of clients from the Windows/.NET world like WebSocketSharp.