-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Support Set-Cookie headers in endpoints #4375
Comments
Yeah, this is annoying, especially considering not all adapters use the |
Given that different platforms workaround this issue in different ways, there's really nothing we can do — we can't monkey-patch the Unless and until consensus among platforms is reached, it will continue to be necessary to return a POJO with an array for |
We wouldn't need to monkey-patch the platform's implementation. When receiving one, we could instead wrap them in the adapter-specific polyfill. Alternatively, we could require and use a standalone Granted, it'd still be annoying, but doable, no? |
Well, we'd need to replace the global |
Closing as this stuff is now handled by |
Describe the problem
If your endpoint returns a
Headers
object that containsSet-Cookie
header(s), you get an error:kit/packages/kit/src/runtime/server/page/load_node.js
Lines 498 to 503 in 2d6f0d2
because, as was pointed out in the PR adding this, dealing with
Set-Cookie
headers is a PITA, andheaders.get("Set-Cookie")
returns some monstrosityDescribe the proposed solution
Since Kit is using
node-fetch
v3, ifheaders
is the output of afetch
, you can callheaders.getAll("Set-Cookie")
to get a nice array ofSet-Cookie
headers. Instead of erroring, it would be nice if Kit could just do this automatically--that way, as a user you can make afetch
inside your endpoint and simply pass along the result'sheaders
object without having to deal with this manually.Note that there's an open PR that might remove this
getAll
method innode-fetch
v4: node-fetch/node-fetch#1484 In this case, the implementation would be changed to use this package: https://www.npmjs.com/package/fetch-headers which also provides a way of extracting multipleSet-Cookie
headers--when iterating over theheaders
object, eachSet-Cookie
will appear as its own header. Details are on the npm page.Alternatives considered
Users can use
headers.getAll
themselves to manually forward the Set-Cookie headers:This works fine but isn't very discoverable & could break if SvelteKit updates its
node-fetch
version.Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: