Skip to content

Commit 0d304d2

Browse files
committed
fix(http): Set content-length only if body is present
1 parent 5c0e121 commit 0d304d2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.changeset/giant-days-develop.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
fix(http): Set content-length only if body is present
6+
7+
The body is undefined when using the edge converter and the method is GET or HEAD

packages/open-next/src/http/request.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ export class IncomingMessage extends http.IncomingMessage {
2828
destroy: Function.prototype,
2929
});
3030

31-
if (typeof headers["content-length"] === "undefined") {
32-
headers["content-length"] = Buffer.byteLength(body).toString();
31+
// Set the content length when there is a body.
32+
// See https://httpwg.org/specs/rfc9110.html#field.content-length
33+
if (body) {
34+
headers["content-length"] ??= String(Buffer.byteLength(body));
3335
}
3436

3537
Object.assign(this, {

0 commit comments

Comments
 (0)