Skip to content

fix(method-override): add duplex option when body is a ReadableStream#5022

Open
LeSingh1 wants to merge 1 commit into
honojs:mainfrom
LeSingh1:fix/method-override-query-duplex
Open

fix(method-override): add duplex option when body is a ReadableStream#5022
LeSingh1 wants to merge 1 commit into
honojs:mainfrom
LeSingh1:fix/method-override-query-duplex

Conversation

@LeSingh1

Copy link
Copy Markdown
Contributor

The query override branch passes c.req.raw.body (a ReadableStream) directly to new Request() without setting duplex: 'half'. The Fetch spec requires this option whenever the request body is a stream, and undici (the native fetch implementation in Node.js) enforces it with:

TypeError: RequestInit: duplex option is required when sending a body.

This means any HTML form that submits to a route using query-based method override will get a 500, because forms always send a body.

The form and header branches are not affected. They consume the body into FormData or URLSearchParams before constructing the new request, so the stream is already resolved by the time new Request() is called.

The fix spreads { duplex: 'half' } into the RequestInit only when body is non-null, and casts to RequestInit because the TypeScript lib types do not yet include duplex.

Added a regression test: a POST ?_method=DELETE with a application/x-www-form-urlencoded body. The existing test for the query branch only used a bodyless POST.

Fixes part of #5010.

The query override branch rebuilds the request from c.req.raw.body, which
is a ReadableStream. The Fetch spec requires duplex: 'half' on RequestInit
when the body is a stream; undici (Node.js native fetch) enforces this and
throws TypeError: duplex option is required when sending a body.

The form and header branches consume the body into a FormData or URLSearchParams
before constructing the new Request, so they are unaffected. Only the query
branch passes the raw stream directly.

Adds a regression test for a body-bearing POST with query override.
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.

1 participant