H3 · H30016
Read the request body once
Flags a handler that reads the request body twice, or reads it and then proxies the request.
Run this rule
pnpm vite-doctor . --rules h3/body/no-double-body-read
Why it matters
H3 v2 uses the Web Request stream. If a body is present and the first read consumes it, a second read can fail and the original stream can no longer be forwarded by a proxy.
Recommended fix
Read the body once and reuse it, or read from a clone before forwarding the original stream to a proxy.
Useful links
Example
Read the body once
Before
export default defineHandler(async (event) => {
await audit(await readBody(event))
return save(await readBody(event))
})
After
export default defineHandler(async (event) => {
const body = await readBody(event)
await audit(body)
return save(body)
})