gevent-socketio
gevent-socketio copied to clipboard
Flashsocket transport ignores HttpOnly cookies in Django
I'm trying to use gevent-socketio with Django. When 'flashsocket' transport is used, all HttpOnly cookies are excluded from request cookies. Since Django sessions system stores an HttpOnly cookie sessionid, user is never authenticated inside recv_connect handler. Also some browsers (at least IE8) cause exceptions when the page is refreshing.
The first is raised immediately after query
"GET /socket.io/1//408631057146/?disconnect=1 HTTP/1.1" 500 53777 0.094426
(Here's another thing that makes me confused: the server fails silently with 500 status every time the page is refreshing, regardless of which transport is used. Is that normal?) Exception is:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 390, in run
result = self._run(*self.args, **self.kwargs)
File "/usr/local/lib/python2.7/dist-packages/socketio/transports.py", line 242, in read_from_ws
message = websocket.receive()
File "/usr/local/lib/python2.7/dist-packages/geventwebsocket/websocket.py", line 93, in receive
raise WebSocketError("Received an invalid frame_type=%r" % frame_type)
WebSocketError: Received an invalid frame_type=255
<Greenlet at 0x9d3fa2c: read_from_ws> failed with WebSocketError
The second is raised after page loaded and recv_connect occured:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent/greenlet.py", line 390, in run
result = self._run(*self.args, **self.kwargs)
File "/usr/local/lib/python2.7/dist-packages/socketio/transports.py", line 232, in send_into_ws
websocket.send(message)
File "/usr/local/lib/python2.7/dist-packages/geventwebsocket/websocket.py", line 31, in send
self._write("\x00" + message + "\xFF")
File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 509, in sendall
data_sent += self.send(_get_memory(data, data_sent), flags)
File "/usr/local/lib/python2.7/dist-packages/gevent/socket.py", line 483, in send
return sock.send(data, flags)
error: [Errno 32] Broken pipe
<Greenlet at 0x9d3fa7c: send_into_ws> failed with error
Server code is pretty simple:
from django.http import HttpResponse
from socketio.namespace import BaseNamespace
from socketio import socketio_manage
class MyNamespace(BaseNamespace):
def recv_connect(self):
print 'User %s is now connected' %self.request.user
print self.request.COOKIES
def socketio(request):
socketio_manage(request.environ, {'/my_ns': MyNamespace}, request)
return HttpResponse()
The project runs on plain SocketIOServer.
Versions of packages I use: gevent – 0.13.7 gevent-websocket – 0.3.6 gevent-socketio – 0.3.5-rc2 socket.io-client – 0.9.9, also tried 0.9.1-1
@eventlistener The server crash issue should no longer be a problem.
Can you provide a django sample app that shows this problem with HttpOnly cookies. The websocket protocol does accept them so if you can provide us a broken example we will fix it.
@eventlistener I meant in the form of a pull request to /examples if that wasn't clear. We use those as our testbed.
@eventlistener Ping.