-
Hello Undici community! I'd like to understand the behavior in a very specific corner case. Maybe it's intended. I have this endpoint which returns a 302 redirection to another route, with a stream body containing a0a1a2a3a4a5. When fetched with curl the body is displayed. curl command & results
When fetched with Undici, the request is aborted and fails if one attempts to consume the body (reproduction), as opposed to node-fetch. The spec (step #8)) provides guidance about redirection with body over http2, but also states that the client should return the response. What's your take? Here's the endpoint code, for the curious
// running on vercel, edge function
export default function handle(request) {
const location = new URL('/api/route', request.url)
const stream = new ReadableStream({
start(controller) {
let count = 0
const l = setInterval(() => {
controller.enqueue('a' + count++)
if (count > 5) {
controller.close()
clearInterval(l)
}
}, 100)
},
})
return new Response(stream, { status: 302, headers: { location } })
}
export const config = { runtime: 'experimental-edge' } |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
cc @KhafraDev could you take a look? |
Beta Was this translation helpful? Give feedback.
-
Yes, this appears to be a mistake in undici (step 8.1, as mentioned). The connection is destroyed here: Line 1051 in 6a87bfb Which then aborts the request here: Line 1553 in 6a87bfb which you can then follow the stack trace, but is relatively unimportant. The connection should not be destroyed because undici doesn't support http/2. You could submit a PR to remove this line with a reproducible example or I can (a little busy atm). |
Beta Was this translation helpful? Give feedback.
-
Here's the PR: #1627 |
Beta Was this translation helpful? Give feedback.
Here's the PR: #1627