Fix #118 - toResponse overwrites multiple Set-Cookie headers#119
Open
rastislavcore wants to merge 1 commit intobetter-auth:mainfrom
Open
Fix #118 - toResponse overwrites multiple Set-Cookie headers#119rastislavcore wants to merge 1 commit intobetter-auth:mainfrom
rastislavcore wants to merge 1 commit intobetter-auth:mainfrom
Conversation
toResponse overwrites multiple Set-Cookie headers
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.
Summary
When building a
Response,toResponse()merged headers withheaders.set(key, value). For repeated header names,Headers#set()overwrites the previous value, so only oneSet-Cookiewas kept. Endpoints that set several cookies (e.g. session token, session_data, dont_remember) only sent one cookie to the client, so the session cookie was often dropped and the user did not appear logged in.This change uses
headers.append(key, value)for theset-cookieheader when copying/merging headers, so everySet-Cookieline is preserved in the final response.Changes
src/to-response.ts: When copying headers (Response branch and all three merge points in the_flag=jsonbranch), useappendforset-cookieandsetfor other headers.src/to-response.test.ts: New describe block "Set-Cookie header preservation" with three tests:_flag=jsonwithinit.headersrouterResponse.headersin_flag=jsonTesting
npm testin the package:to-response.test.tspasses (32 tests including the 3 new ones).Closes #118.