-
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
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 :-) |
I would be happy to match the logic from CPython requests to the best that we can. Thanks for looking into it @justmobilize |
@FoamyGuy would like you thoughts. I went down the rabbit-hole and got: in Cpython
All this to say that the socket takes care of this. So I see 2 options:
I would prefer option 1, because I think we would keep fixing things where the socket code isn't handling things right. |
Looking a little bit more, I see when using
which then does:
which just sits there... Everything I read and know, you should always have I did check a Hue (since #123 is what added that) and it indeed doesn't return a I'm going to dig a little more, to try to find the right fix |
okay, @FoamyGuy finally found it in http/client.py
I think we can move this logic into |
@justmobilize that works for me, do you want to PR that change? we can close this one. I'll submit it in another day or two if you are unable. |
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