Skip to content

fix(listener): do not send a complete response when the body fails during the early read - #414

Open
sarankumar1325 wants to merge 1 commit into
honojs:mainfrom
sarankumar1325:fix/early-read-body-error
Open

sarankumar1325 wants to merge 1 commit into
honojs:mainfrom
sarankumar1325:fix/early-read-body-error

Conversation

@sarankumar1325

Copy link
Copy Markdown

Fixes #413

When a handler returns a native Response (for example with overrideGlobalObjects: false) whose body errors during the early read in responseViaResponseObject, the error was logged and treated as the end of the body. The listener then set Content-Length to whatever had been read so far and ended the response, so the client got a complete 200 with an empty body (or a truncated one, if a chunk had been read before the error).

Now an error from the early read is passed to handleResponseError, the same handler the streaming paths use. Since no head has been sent yet, the client gets a 500 instead of a complete success.

Tests

Two new cases in test/listener.test.ts, using a native Response:

  • the body errors before its first chunk;
  • the body enqueues a chunk and then errors, both inside the early read.

Both fail on main (status 200) and pass with this change. vitest run (505 tests), eslint src test, tsc --noEmit and prettier --check all pass.

I used an AI assistant to help write this change and checked the result myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A body failing before its first chunk is sent as a complete, empty 200 when overrideGlobalObjects is false

1 participant