-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
docs: fix issue in cookie passing example #28223
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -466,13 +466,13 @@ Be very careful before proxying headers to an external API and just include head | |
| If you want to pass on/proxy cookies in the other direction, from an internal request back to the client, you will need to handle this yourself. | ||
|
|
||
| ```ts [composables/fetch.ts] | ||
| import { appendResponseHeader, H3Event } from 'h3' | ||
| import { appendResponseHeader, H3Event, splitCookiesString } from 'h3' | ||
|
|
||
| export const fetchWithCookie = async (event: H3Event, url: string) => { | ||
| /* Get the response from the server endpoint */ | ||
| const res = await $fetch.raw(url) | ||
| /* Get the cookies from the response */ | ||
| const cookies = (res.headers.get('set-cookie') || '').split(',') | ||
| const cookies = splitCookiesString(res.headers.get('set-cookie') || '') | ||
|
Member
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. We can instead also use native headers.getSetCookie that returns properly splitter cookies (please double check if works within current nitro v1 env)
Member
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. works well!
Contributor
Author
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. Even nicer! Sorry I was to late to the party to safe you the work, as I see it's already fixed. |
||
| /* Attach each cookie to our incoming Request */ | ||
| for (const cookie of cookies) { | ||
| appendResponseHeader(event, 'set-cookie', cookie) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Please use
splitSetCookieStringfromcookie-esdirectly