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

fix: prevent duplication of location header #369

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc, we had to handle this case specifically for middleware Redirects. Can you verify that it works with this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, i`ve tested it by patching 2.3.6 version. Maybe I need to cover this case by some tests? Do you have any contributing docs?

Copy link
Collaborator

@khuezy khuezy Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.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
Loading