Skip to content

Commit 0975444

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

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
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: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66
import http from "node:http";
77

88
export class IncomingMessage extends http.IncomingMessage {
9-
constructor({
10-
method,
11-
url,
12-
headers,
13-
body,
14-
remoteAddress,
15-
}: {
9+
constructor(request: {
1610
method: string;
1711
url: string;
1812
headers: Record<string, string | string[]>;
1913
body?: Buffer;
2014
remoteAddress?: string;
2115
}) {
16+
const { method, url, headers, body, remoteAddress } = request;
17+
2218
super({
2319
encrypted: true,
2420
readable: false,
@@ -28,8 +24,10 @@ export class IncomingMessage extends http.IncomingMessage {
2824
destroy: Function.prototype,
2925
});
3026

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

3533
Object.assign(this, {

0 commit comments

Comments
 (0)