Skip to content

Commit

Permalink
fix(http): Set content-length only if body is present (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored Nov 21, 2024
1 parent 5c0e121 commit fe600ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/giant-days-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@opennextjs/aws": patch
---

fix(http): Set content-length only if body is present

The body is undefined when using the edge converter and the method is GET or HEAD
6 changes: 4 additions & 2 deletions packages/open-next/src/http/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ export class IncomingMessage extends http.IncomingMessage {
destroy: Function.prototype,
});

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

Object.assign(this, {
Expand Down

0 comments on commit fe600ac

Please sign in to comment.