-
-
Notifications
You must be signed in to change notification settings - Fork 540
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
Accessing HTTP connection response body for debugging #795
Comments
Probably, the fastest solution will be to patch the library around here: Add something along the lines of Definitely something worth improving, at least for simple cases (e.g. when there's a |
Thanks! |
#676 (WIP) parses HTTP response bodies in the easy cases (no Transfer-Encoding) which is a good step towards getting this done. |
If anyone is interested I'm patching it in the way below. Just call
|
Out of curiosity, what is the reasoning for not supporting chunked Transfer-Encoding? I notice you reference section 3.3.3 of the HTTP RFC in the code, but I didn't see anything in the RFC that would prevent you from processing the body of the response (as long as the final encoding is chunked). Maybe something like this... if 100 <= status_code < 200 or status_code == 204 or status_code == 304:
body = None
else:
if "Transfer-Encoding" in headers:
if headers["Transfer-Encoding"] == "chunked":
body = b""
while True:
# The first line contains the chunk size
chunksize = yield from parse_line(read_line)
n = int(chunksize, 16)
if n > 0:
body += yield from read_exact(n + 2)
else:
# Chunksize is 0, consume the last line
data = yield from parse_line(read_line)
assert not data
break
else:
raise NotImplementedError(
f"'{headers["Transfer-Encoding"]}' transfer codings aren't supported"
)
else:
# Do content length stuff... |
The reason is that I'm maintaining a WebSocket library, not a HTTP library. Deciding not to implement a HTTP library is purely a decision of where I want to spend my free time :-) |
It will always be possible to move the line "just a bit". At some point I have to draw the line. I believe that the place where it's currently drawn covers reasonable use cases of websockets as a WebSocket client. If you come across a use case where support for Transfer-Encoding would be needed, I will assess if I deem that use case reasonable to support :-) |
This is now available in Sans-I/O implementation, the threading implementation, and the new asyncio implementation that was just merged to the main branch (#1332), which solves this issue. I'm not going to add it to the legacy asyncio implementation. |
Hi!
I'm trying to debug failing connection attempts, probably an authentication issue with our API gateway.
The gateway server responds with a 400, refusing the connection. The websockets debug logs show the response status and headers, but not the response body, which in this case should contain an error message.
Is there a way to have the library output the response body as well?
I would have tried using a proxy like https://docs.mitmproxy.org to monitor the http exchange, but the library doesn't support connecting through such a proxy.
Thanks!
The text was updated successfully, but these errors were encountered: