-
Notifications
You must be signed in to change notification settings - Fork 138
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,18 +123,13 @@ 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}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure this will work on every case, what if you set the uppercase There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here i mentioned that it doesn't matter uppercase or lowercase, key will be lowercase always |
||
// res.setHeader("Location", location); | ||
return { | ||
body: "", | ||
type: internalEvent.type, | ||
statusCode: res.statusCode, | ||
headers: { | ||
...resHeaders, | ||
Location: location ?? "", | ||
}, | ||
headers: resHeaders, | ||
isBase64Encoded: false, | ||
}; | ||
} | ||
|
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we have this covered
App: https://github.com/sst/open-next/blob/main/examples/app-router/middleware.ts#L8