KeyError: 'HTTP_SEC_WEBSOCKET_KEY'
Hi,
I've deployed successfully django-websocket-redis, working fine. Good job!
The issue here are with certain client, specifically Safari on iOS 5.1 (which is claimed to support WebSockets) raise the error:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/ws4redis/wsgi_server.py", line 72, in call websocket = self.upgrade_websocket(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/ws4redis/uwsgi_runserver.py", line 52, in upgrade_websocket uwsgi.websocket_handshake(environ['HTTP_SEC_WEBSOCKET_KEY'], environ.get('HTTP_ORIGIN', ''))
KeyError: 'HTTP_SEC_WEBSOCKET_KEY'
Request repr() unavailable.
Any hints? Deployed with uwsgi with gevent support, behing nginx.
I can reproduce the issue regularly with the ipad above..
Thanks.
Interesting. We then should access the environ using environ.get('HTTP_SEC_WEBSOCKET_KEY') or just disable it for these kinds of clients. As far as I know, the HTTP-request header Sec-Websocket-Key is mandatory for as WS handshake, so, or Safari uses another name or it just can't do it.
Looking around, seems that such version of Safari won't send the correct header, so I've to exclude/disable the feature for them. I'd really like to have ws4redis handle this, but in the mean time, do you have any suggestions to handle the issue nicely?
Upgrade Safari? :)
Which iOS is it running on?
It's not mine, it's a user of the web application.. it's an Ipad 1, with iOS 5.1.
Oddly, using such tablet on https://www.websocket.org/echo.html states that websockets are fully supported.
Upgrade, unfortunately, it's not possible on a such old device. Disabling the feature for them is fine anyway, so I'm handling it, but I think that ws4redis is the right place where to handle this kind of issues.
If I can help somehow, let me know!
can I close this?
Are there any solution to handle nicely the missing "HTTP_SEC_WEBSOCKET_KEY" from environ, maybe using get() method with a default?
Nope, please read https://tools.ietf.org/html/rfc6455#section-11.3.1
I certainly will not introduce non-standard behavior as a workaround for broken clients.
No one is asking for that, of course :) I'm just suggesting to handle the case that the HTTP_SEC_WEBSOCKET_KEY is missing, to raise a more specific exception, for example, rather than KeyError, to have it managed elsewhere.
yes, this certainly.