Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H3 - stripping body from request when received with transfer-encoding:chunked #651

Open
benlavalley opened this issue Feb 11, 2024 · 1 comment · May be fixed by #652
Open

H3 - stripping body from request when received with transfer-encoding:chunked #651

benlavalley opened this issue Feb 11, 2024 · 1 comment · May be fixed by #652

Comments

@benlavalley
Copy link

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

@aaharu
Copy link

aaharu commented Feb 16, 2024

It may be related to the following issue.
#197

@aaharu aaharu linked a pull request Feb 17, 2024 that will close this issue
8 tasks
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 a pull request may close this issue.

2 participants