fix: do not discard already present set-cookie header #327
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.
This PR aims at fixing the current behavior of
nuxt-i18n
when setting the detected language cookie.If someone were to set a cookie within a Nuxt server-middleware (e.g. a CSRF token cookie), it will be discarded only the first time
nuxt-i18n
is setting the language redirection cookie.The root cause comes from using
res.setHeader('Set-Cookie', redirectCookie)
: it no longer implicitly append the cookie value to the current list ofSet-Cookie
values in Express > 4, as explained here: https://github.com/expressjs/express/wiki/Migrating-from-3.x-to-4.x#ressetheaderset-cookie-valTo keep compatibility of this middleware with requests/responses from Express/Connect/etc., using the
cookies
package instead ofcookie
seems like a sensible choice to me, and fixes nicely the issue.If I missed something while refactoring the code, please let me know so we can find the most elegant and robust solution.