Unreliable checking of HTTP 200 response string
In transports.py, there is an assert statement that checks responses for the string "ok":
class XHR_PollingTransport(AbstractTransport):
...
def send_packet(self, engineIO_packet_type, engineIO_packet_data=''):
...
response = get_response(
self.http_session.post,
self._http_url,
params=params,
data=memoryview(data),
**self._kw_post)
assert response.content == b'ok'
This code fails when a 200 status response is returned with the string "OK" instead of "ok". To make the code work with the Flask-SocketIO python package, I had to make the following change:
assert response.content in [b'ok', b'OK']
However, I believe both versions of the assert statement are redundant because it appears the response status code is already being checked in get_response():
def get_response(request, *args, **kw):
...
status_code = response.status_code
if 200 != status_code:
raise ConnectionError('unexpected status code (%s %s)' % (
status_code, response.text))
return response
An HTTP 200 "OK" response will pass the check in get_response() but fail the check in send_packet(), but an HTTP 200 "ok" response will pass both checks.
I've just come across this issue as well. The client was complaining the status code wasn't 'ok' yet I could only see 200 response codes from my flask server. I did wonder if it was something as simple as different case...
Would be great if this fix could be included!
I'm also running into this issue using python-socketio as the server. I haven't tested with other servers.
@kcgh thank you for reporting this issue in great detail! @bodgit thank you for submitting the fix!
pip install -U socketIO-client