-
Notifications
You must be signed in to change notification settings - Fork 382
feat: Add feature to parse multiple set-cookies #688
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
Conversation
Thanks for the PR! Some thoughts:
|
Thanks for your feedback @devoncarew ! This is exactly what I was thinking too. I used to get an error in static analysis when I uploaded a package I was developing that used And now I have scrutinized the Thank you. |
lib/src/base_response.dart
Outdated
@@ -2,6 +2,8 @@ | |||
// for details. All rights reserved. Use of this source code is governed by a | |||
// BSD-style license that can be found in the LICENSE file. | |||
|
|||
import 'dart:io'; |
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 for Cookie
.
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
)
extension Cookies on Response {
List<Cookie> get cookies {
// ...
}
}
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 to dart: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 a Cookie
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.
extension Cookies on Response {
List<Cookie> get cookies {
// ...
}
}
FYI this is related to #24 which proposes a different approach |
test/response_test.dart
Outdated
for (final cookie in response.cookies) { | ||
expect( | ||
cookie.name, | ||
anyOf([ |
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.
this makes the test pass if response.cookies
is always just a single cookie, e.g. the first one, repeated 6 times. This isn't so unimaginable in case of an error in the parsing code.
up ,there's still an issue about parsing multiple set-cookies now , all set-cookies will be covered by last one |
db07459
to
79470d0
Compare
Hi amazing developers,
Perhaps this is already on the agenda before, but the
http
library combines multipleset-cookie
s in the response header into a comma-separated list that is set in theheaders
field. This is a rather complicated specification and not one that developers can easily handle.Therefore, I have added the feature to parse
set-cookie
s contained inheaders
to make it easier to handle multipleset-cookie
s. This modification is not disruptive and theheaders
field will continue to function as before.However, in the future you need to reintegrate
cookies
field when you make theheaders
field an object, as was written in theBaseResponse
TODO.Also it was necessary to add
universal_io
to the dependencies to useCookie
object.Thank you.