sst / open-next

Open source Next.js serverless adapter
https://open-next.js.org
MIT License
3.7k stars 111 forks source link

Duplicating location header #368

Closed r34son closed 4 months ago

r34son commented 4 months ago

I'm using next-intl. Server function handles redirect from middleware, but there is an issue that it duplicates location header because of case mismatch.

"headers": {
    "location": "https://someurl.com/some-path",
    "Location": "https://someurl.com/some-path"
},
r34son commented 4 months ago

https://github.com/sst/open-next/blob/3deb2022d0bb506e4c4b66baeae248c7c2b153e5/packages/open-next/src/adapters/routing/middleware.ts#L125-L140

Here resHeaders contain location key. It's strange that you get location header and assign it to Location key. I can open a PR that fixes this behavior, if you approve that it's real issue.

khuezy commented 4 months ago

Clients and servers are suppose to handle either casing right? But in general, they should be pascal casing. Can you figure out where/what is setting it to the lower case location and fix that? If that's somewhere upstream, then we should delete it from the resHeaders to remove the duplication.

r34son commented 4 months ago

It breaks app, because by design 2 same http headers are combined in one, values in which are separated by commas. https://www.rfc-editor.org/rfc/rfc9110.html#name-field-lines-and-combined-fi

Also realised that header names are lowercase in https://developer.mozilla.org/en-US/docs/Web/API/Headers

image

I'll open pr that changes Location to location.