-
-
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
Cookie Header should be Map-like #1145
Comments
For implementation, something like the So, it could look like: pub struct Cookie(VecMap<Cow<'static, str>, Cow<'static, str>>);
impl Cookie {
pub fn new() -> Cookie;
pub fn get(&self, name: &str) -> Option<&str>;
pub fn set<K: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>>(&mut self, name: K, value: V);
} |
What is the process to inject a breaking change? |
Well, a breaking change would require a version bump (since we're before 1.0, that means the minor version). Good news is that we're about to do that anyways, with the async changes, to 0.11. So, if done quickly, it can ride that breakage together. Regarding duplicate cookie names, I just did some more searching. The situation is worse than I thought. The spec explicitly leaves it undefined when there are multiple cookies with the same name. "[...] servers SHOULD NOT rely upon the order in which these cookies appear in the header." Thanks, RFC. It seems many libraries in many languages just grab the first one. That may not be the behavior determined in the spec, but it seems like it has become the de-facto behavior. The internet is fun... |
My understanding is that servers should not rely on it, but because all clients send cookies the same way (narrower, more pertinent scope first), accepting the first key of a series of duplicate is what all servers do, and not doing so could create security issues. Should I take a first stab at implement a new struct for the "Cookie" header, something along the method in #1142, but as the struct instead? |
That should be fine. And anyone really needing the duplicate headers can always check |
The `Cookie` header now has `get` and `set` methods, to tree the list of cookies as a map. BREAKING CHANGE: The `Cookie` header is no longer a wrapper over a `Vec<String>`. It must accessed via its `get` and `set` methods. Closes #1145
The `Cookie` header now has `get` and `set` methods, to tree the list of cookies as a map. BREAKING CHANGE: The `Cookie` header is no longer a wrapper over a `Vec<String>`. It must accessed via its `get` and `set` methods. Closes #1145
The `Cookie` header now has `get` and `append` methods, to tree the list of cookies as a map. BREAKING CHANGE: The `Cookie` header is no longer a wrapper over a `Vec<String>`. It must accessed via its `get` and `append` methods. Closes #1145
The `Cookie` header now has `get` and `append` methods, to tree the list of cookies as a map. BREAKING CHANGE: The `Cookie` header is no longer a wrapper over a `Vec<String>`. It must accessed via its `get` and `append` methods. Closes #1145
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 has 'set' and `get` methods, to treat the list of cookies as a map. Closes hyperium#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.
We only ever receive headers like this:
Cookie: foo=bar; session=sean; hello=world
, and having that be a vector of["foo=bar", "session=sean", "hello=world"]
doesn't really help anyone.Instead, anyone needing to accept cookies would only be looking for a certain name anyways, so this code would be more appropriate:
Being a map also helps deal with a common mistake naïve users could make: duplicate names should just be dropped.
Creation of a
Cookie
header should likewise use a map-like interface.The text was updated successfully, but these errors were encountered: