-
Notifications
You must be signed in to change notification settings - Fork 35
Dont try to read body of 204 no_content resp #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@FoamyGuy I was going to tackle this tomorrow. The Python requests library doesn't do this based on status code, and think we should try to match their logic, thoughts? |
200 without My understanding (which is shallow) is that CPython can detect when the server closes the socket, using 204 by definition has no response body: I may be missing a third way, but it seems we either need to condition on status code, or add capability to sense that the server has closed the socket (supporting ESP32SPI, WIZnet, and two native implementations). Otherwise, that leaves timeout. In an environement where I can control the server to respond with a 204, the headers are:
No response body (and not chunked), no |
A quick look, and that PR uses So the correct fix would see that |
I'm just wondering if that something needs to be a timeout, or if there's some other mechanism in the absence of content-length, chunked, or socket close. It doesn't seem like curl or CPython Requests have any discernable timeout. If not conditioning on status code, a 200 is like a 204 except it has no body (a 200 could also have no body, but then it should have a content-length header of 0), but the client may not know there are no body bytes incoming without waiting to see? |
My plan was to step through a normal 204 in CPython requests and see what it gets. And then see if I can reproduce it in a 3 in circuitpython... |
I'm glad you all are on it. I'm baffled how it works given all of the above :-) |
Resolves: #210
With this change the behavior now matches between CircuitPython and CPython
circuitpython:
CPYthon:
Without this change the code goes into
iter_content()
which gets to readinto and stalls until timeout as there is no data to read.I am not certain if this is the correct / best way to handle 204 responses, but it does seem to match the behavior of CPython. I tried poking around briefly in the CPYthon requests code to look for any special handling of 204 status like this and couldn't find any so I'm not sure what drives the behavior on CPython.
All of my testing was on ESP32S3 TFT with 9.2.7