-
Notifications
You must be signed in to change notification settings - Fork 24
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
Parsing set-cookie #30
Comments
Potentially more could be added here, but it should be backward compatible. I wonder if the |
I think I took a look at
I still think it would be nice to have the functionality in |
use http::header::SET_COOKIE;
let mut headers = http::HeaderMap::new();
for h in &[
"cookie_1=value 1; path=/path; Domain=example.com; \
Expires=Wed, 30 Nov 2020 13:28:00 GMT",
"cookie_2=valu%C3%A9 2; path=/; Domain=par.example.com; \
Expires=Wed, 29 Nov 2020 18:00:00 GMT" ] {
headers.append(SET_COOKIE, h.parse().unwrap());
}
// Parse all set-cookie headers, excluding non-ASCII values or other parse
// errors.
let cookies: Vec<_> = headers.get_all(SET_COOKIE)
.iter()
.filter_map(|hv| hv.to_str().ok())
.filter_map(|vs| cookie::Cookie::parse_encoded(vs).ok())
.collect();
assert_eq!(cookies.len(), 2);
assert_eq!(cookies[0].name(), "cookie_1");
assert_eq!(cookies[0].path(), Some("/path"));
assert_eq!(cookies[1].name(), "cookie_2");
assert_eq!(cookies[1].value(), "valué 2");
assert_eq!(cookies[1].expires().map(|t| t.month()), Some(11)) Or for lookup by name, a |
Added docs and reference to the above usage example in 0b05e9a (main). |
Hi, thanks for your work on hyperx.
Currently,
hyperx::headers::SetCookie
is just a newtype forVec<String>
, each string looking something like"lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT"
. I think it would be nice if the header was a bit easier to work with, I was initially hoping for an interface closer tohyperx::headers::Cookie
. For my specific use case, I just need the cookie name and value which are easy enough to parse manually, but I imagine if you need to read some of the other properties that can be included it might be a bit trickier. Would this kind of functionality have a place in hyperx?Thanks.
The text was updated successfully, but these errors were encountered: