Skip to content

Commit

Permalink
fix: prevent duplication of location header (#369)
Browse files Browse the repository at this point in the history
* fix: prevent duplication of location header

* changeset

* fix linting

---------

Co-authored-by: conico974 <nicodorseuil@yahoo.fr>
  • Loading branch information
r34son and conico974 authored Mar 6, 2024
1 parent af2d3ce commit 3235392
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-students-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"open-next": patch
---

fix: prevent duplication of location header
12 changes: 5 additions & 7 deletions packages/open-next/src/adapters/routing/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,16 @@ export async function handleMiddleware(
// If the middleware returned a Redirect, we set the `Location` header with
// the redirected url and end the response.
if (res.statusCode >= 300 && res.statusCode < 400) {
const location = result.response.headers
.get("location")
?.replace("http://localhost:3000", `https://${req.headers.host}`);
resHeaders.location = resHeaders.location?.replace(
"http://localhost:3000",
`https://${req.headers.host}`,
);
// res.setHeader("Location", location);
return {
body: "",
type: internalEvent.type,
statusCode: res.statusCode,
headers: {
...resHeaders,
Location: location ?? "",
},
headers: resHeaders,
isBase64Encoded: false,
};
}
Expand Down

0 comments on commit 3235392

Please sign in to comment.