docs: fix issue in cookie passing example #28223
Merged
Conversation
This splits them without choking on commas that are within a single set-cookie field-value, such as in the Expires portion.
|
|
danielroe
approved these changes
Jul 19, 2024
pi0
reviewed
Jul 19, 2024
|
|
||
| ```ts [composables/fetch.ts] | ||
| import { appendResponseHeader, H3Event } from 'h3' | ||
| import { appendResponseHeader, H3Event, splitCookiesString } from 'h3' |
Member
There was a problem hiding this comment.
Please use splitSetCookieString from cookie-es directly
pi0
reviewed
Jul 19, 2024
| 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.
We can instead also use native headers.getSetCookie that returns properly splitter cookies (please double check if works within current nitro v1 env)
Contributor
Author
There was a problem hiding this comment.
Even nicer! Sorry I was to late to the party to safe you the work, as I see it's already fixed.
Merged
Member
|
Sorry, didn't spot your comments @pi0! |
danielroe
pushed a commit
that referenced
this pull request
Jul 23, 2024
Kamsou
pushed a commit
to Kamsou/nuxt
that referenced
this pull request
Feb 5, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.