-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(header): change Cookie
to be map-like
#1152
Conversation
Ah. That's unfortunate. I'm working on a different implementation, but had problems fighting the borrow checker... Now I actually believe a map is not the right structure for the cookie header. This is what I was working on... Take a look, maybe what I am saying here will make more sense. Keep in mind that some of the complication in there is due to trying to work around the borrow checker: https://is.gd/MxBTqt |
@dorfsmay thats ok! I wasn't sure if you were, and I was hoping to get this in before tagging 0.11, so that's why I worked on this. But it's good also, because you bring up an interesting point. Clients (such as Servo) would want to push all cookies that relate to a certain resource, even if they have the same name... |
When do you plan to release 0.11? Maybe I can just use memory for now to get it in, and work on making reference from the Hash (VecMap) to the Vec later as an improvement... |
To get the desired semantics, what if let mut cookie = Cookie::new();
cookie.append("foo", "bar");
cookie.append("foo", "otherbar");
assert_eq!(cookie.to_string(), "foo=bar; foo=otherbar"); |
I actually like the solution let mut cookie = Cookie::new();
cookie.append("foo", "bar");
cookie.append("foo", "otherbar");
assert_eq!(cookie.to_string(), "foo=bar; foo=otherbar");
cookie.set("foo", "baz");
assert_eq!(cookie.to_string(), "foo=baz"); |
2a046ae
to
f2a3081
Compare
I'm happy with happy append (or push in my solution above) vs set, but get has to return the first value, that was set/appended for that key, because that is the way everybody expect servers to work. Client are supposed to be appending in order, even duplicate keys. |
The `Cookie` header now has 'set' and `get` methods, to treat the list of cookies as a map. Closes #1145 BREAKING CHANGE: The `Cookie` header is no longer a wrapper over a `Vec<String>`. It must be accessed via its `get` and `append` methods.
The
Cookie
header now hasget
andset
methods, to tree the list ofcookies as a map.
Closes #1145
cc @dorfsmay