Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions httpcore/_async/http11.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ async def _receive_event(self, timeout: TimeoutDict) -> H11Event:

if event is h11.NEED_DATA:
data = await self.socket.read(self.READ_NUM_BYTES, timeout)

# If we feed this case through h11 we'll raise an exception like:
#
# httpcore.RemoteProtocolError: can't handle event type
# ConnectionClosed when role=SERVER and state=SEND_RESPONSE
#
# Which is accurate, but not very informative from an end-user
# perspective. Instead we handle this case distinctly and treat
# it as a ConnectError.
if data == b"" and self.h11_state.their_state == h11.SEND_RESPONSE:
msg = "Server disconnected without sending a response."
raise RemoteProtocolError(msg)

self.h11_state.receive_data(data)
else:
assert event is not h11.NEED_DATA
Expand Down
13 changes: 13 additions & 0 deletions httpcore/_sync/http11.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ def _receive_event(self, timeout: TimeoutDict) -> H11Event:

if event is h11.NEED_DATA:
data = self.socket.read(self.READ_NUM_BYTES, timeout)

# If we feed this case through h11 we'll raise an exception like:
#
# httpcore.RemoteProtocolError: can't handle event type
# ConnectionClosed when role=SERVER and state=SEND_RESPONSE
#
# Which is accurate, but not very informative from an end-user
# perspective. Instead we handle this case distinctly and treat
# it as a ConnectError.
if data == b"" and self.h11_state.their_state == h11.SEND_RESPONSE:
msg = "Server disconnected without sending a response."
raise RemoteProtocolError(msg)

self.h11_state.receive_data(data)
else:
assert event is not h11.NEED_DATA
Expand Down