-
-
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
Conversation
This splits them without choking on commas that are within a single set-cookie field-value, such as in the Expires portion.
|
|
|
|
||
| ```ts [composables/fetch.ts] | ||
| import { appendResponseHeader, H3Event } from 'h3' | ||
| import { appendResponseHeader, H3Event, splitCookiesString } from 'h3' |
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 splitSetCookieString from cookie-es directly
| 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') || '') |
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.
We can instead also use native headers.getSetCookie that returns properly splitter cookies (please double check if works within current nitro v1 env)
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.
works well!
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.
Even nicer! Sorry I was to late to the party to safe you the work, as I see it's already fixed.
|
Sorry, didn't spot your comments @pi0! |
Use H3's
splitCookiesStringfunction to split the set-cookie header without choking on commas that are within a single set-cookie field-value, such as in the Expires portion.