Replies: 1 comment 7 replies
-
Hmm, I see! Interesting case 😅 I would prefer to keep the normal functioning of the context manager, to keep a good developer experience. Before raising the exception, could we actually read the content? I believe then HTTPX will cache it and make it available immediately on further reads. Something like: async with client.stream("GET", url, headers=headers, **kwargs) as response:
if response.status_code != 101:
await response.aread()
raise WebSocketUpgradeError(response) What do you think? |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the bug
Unable to read the content of
WebSocketUpgradeError.response
, because the stream has already been closed.To Reproduce
Launch a server to send a denial handshake response.
Next, attempt the handshake using
httpx-ws
and read the response content after the handshake fails.Then you can see following error:
Expected behavior
The propagation of
WebSocketUpgradeError
leads to the exit of theclient.stream
context manager, then theresponse
content is no longer readable.httpx-ws/httpx_ws/_api.py
Lines 1048 to 1050 in 940c9ad
Can we make a compromise: request the user to manually close the response when
WebSocketUpgradeError
is raised, instead of closing it automatically?Configuration
Beta Was this translation helpful? Give feedback.
All reactions