feat: Add feature to parse multiple set-cookies - #688
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. |
| // 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.
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.
Thanks for your review @natebosch !
I found several issues have been raised regarding this case of multiple set-cookies, 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 |
| for (final cookie in response.cookies) { | ||
| expect( | ||
| cookie.name, | ||
| anyOf([ |
There was a problem hiding this comment.
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
httplibrary combines multipleset-cookies in the response header into a comma-separated list that is set in theheadersfield. This is a rather complicated specification and not one that developers can easily handle.Therefore, I have added the feature to parse
set-cookies contained inheadersto make it easier to handle multipleset-cookies. This modification is not disruptive and theheadersfield will continue to function as before.However, in the future you need to reintegrate
cookiesfield when you make theheadersfield an object, as was written in theBaseResponseTODO.Also it was necessary to add
universal_ioto the dependencies to useCookieobject.Thank you.