Skip to content
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

fix: do not discard already present set-cookie header #327

Merged
merged 1 commit into from
Jun 21, 2019

Conversation

rclement
Copy link

@rclement rclement commented Jun 21, 2019

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 of Set-Cookie values in Express > 4, as explained here: https://github.com/expressjs/express/wiki/Migrating-from-3.x-to-4.x#ressetheaderset-cookie-val

To keep compatibility of this middleware with requests/responses from Express/Connect/etc., using the cookies package instead of cookie 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.

@codecov
Copy link

codecov bot commented Jun 21, 2019

Codecov Report

Merging #327 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #327   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines           6      6           
=====================================
  Hits            6      6

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c314a9...5165d80. Read the comment docs.

@paulgv paulgv merged commit ec08be8 into nuxt-modules:master Jun 21, 2019
@paulgv
Copy link
Collaborator

paulgv commented Jun 21, 2019

LGTM! Thank you @rclement !

@rchl
Copy link
Collaborator

rchl commented Jun 22, 2019

Another way to fix that would be to get existing cookies and modify the array. Maybe that' better option than introducing this heavier dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants