h3
h3 copied to clipboard
H3 - stripping body from request when received with transfer-encoding:chunked
Environment
Node v18.19.0 H3 1.10.1. MacOS 14.2.1 (Intel)
Reproduction
This can be reproduced with this rep and simply trying to parse an inbound request body received with transfer-encoding:chunked.
Sample mininal app code:
import { createServer } from "node:http";
import { createApp, eventHandler, toNodeListener, readBody } from "h3";
const app = createApp();
app.use(
"/",
eventHandler(async(event) => {
console.log('body: ', await readBody(event));
}),
);
createServer(toNodeListener(app)).listen(process.env.PORT || 3000);
Curl request to reproduce the issue:
curl --location 'http://localhost:3000/api/chunkedtest'
--header 'Content-Type: application/json; charset=utf-8'
--header 'transfer-encoding: chunked'
--data '{"testkey":"testvalue","testkey2":"testvalue2"}'
This request will work:
curl --location 'http://localhost:3000/api/chunkedtest'
--header 'Content-Type: application/json; charset=utf-8'
--header 'Content-Length: 47'
--data '{"testkey":"testvalue","testkey2":"testvalue2"}'
Describe the bug
I spent most of my night troubleshooting an issue with Nuxt and traced it to H3, though honestly the issue could be further upstream now that I've dug into the code. Sending a POST request to H3 with transfer-encoding:chunked (as opposed to traditional content-lenght:XX) in the header will fail - there are no errors thrown, the body is empty after sending requests with Postman or Curl.
Additional context
No response
Logs
No response