-
Notifications
You must be signed in to change notification settings - Fork 341
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
feat: Add feature to parse multiple set-cookies #688
Open
myConsciousness
wants to merge
4
commits into
dart-lang:master
Choose a base branch
from
myConsciousness:master
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,4 +70,50 @@ void main() { | |
expect(response.bodyBytes, equals([104, 101, 108, 108, 111])); | ||
}); | ||
}); | ||
|
||
// If multiple set-cookies are included in the response header, | ||
// the http library will merge them into a comma-separated list | ||
// and set them in the Response object. | ||
test('checks multiple set-cookies', () { | ||
final response = http.Response('', 200, headers: { | ||
'set-cookie': | ||
// This response header contains 6 set-cookies | ||
'AWSALB=AWSALB_TEST; Expires=Tue, 26 Apr 2022 00:26:55 GMT; Path=/,AWSALBCORS=AWSALBCORS_TEST; Expires=Tue, 26 Apr 2022 00:26:55 GMT; Path=/; SameSite=None; Secure,jwt_token=JWT_TEST; Domain=.test.com; Max-Age=31536000; Path=/; expires=Wed, 19-Apr-2023 00:26:55 GMT; SameSite=lax; Secure,csrf_token=CSRF_TOKEN_TEST_1; Domain=.test.com; Max-Age=31536000; Path=/; expires=Wed, 19-Apr-2023 00:26:55 GMT,csrf_token=CSRF_TOKEN_TEST_2; Domain=.test.com; Max-Age=31536000; Path=/; expires=Wed, 19-Apr-2023 00:26:55 GMT,wuuid=WUUID_TEST' | ||
}); | ||
|
||
expect(response.cookies.length, 6); | ||
for (final cookie in response.cookies) { | ||
expect( | ||
cookie.name, | ||
anyOf([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this makes the test pass if |
||
'AWSALB', | ||
'AWSALBCORS', | ||
'jwt_token', | ||
'csrf_token', | ||
'wuuid', | ||
'csrf_token' | ||
])); | ||
expect( | ||
cookie.value, | ||
anyOf([ | ||
'AWSALB_TEST', | ||
'AWSALBCORS_TEST', | ||
'JWT_TEST', | ||
'CSRF_TOKEN_TEST_1', | ||
'CSRF_TOKEN_TEST_2', | ||
'WUUID_TEST' | ||
])); | ||
} | ||
}); | ||
|
||
test('checks a set-cookie', () { | ||
final response = http.Response('', 200, headers: { | ||
'set-cookie': | ||
'AWSALB=AWSALB_TEST; Expires=Tue, 26 Apr 2022 00:26:55 GMT; Path=/' | ||
}); | ||
|
||
expect(response.cookies.length, 1); | ||
expect(response.cookies.first.name, 'AWSALB'); | ||
expect(response.cookies.first.value, 'AWSALB_TEST'); | ||
}); | ||
} |
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.
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't import
dart:io
from this library.universal_io
is intending to get around that problem, but we don't want to take a dependency on that library either. If we wanted to have this functionality in this library we'd have to reimplement an interface forCookie
.This feels like the type of thing that should be added on in a side package (which could more easily have a dependency on
universal_io
)I suppose the nice thing about implementing it here is being able to cache it, but using an
expando
is probably a fine alternative if caching is important. Probably you'll only read.cookies
once anyway.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.
Thanks for your review @natebosch !
I found several issues have been raised regarding this case of multiple
set-cookie
s, and I feel that a fundamental solution is needed. At the same time, I also understood the difficulties related todart:io
. It's quite a deep-rooted problem.It's possible to add a
Cookie
interface and implementation, but is there a reluctance to add aCookie
object as a development policy for the http library?If we can implement
Cookie
interface in http library, I thought the following example was a very good solution.