/// `Cookie` header, defined in [RFC6265](http://tools.ietf.org/html/rfc6265#section-5.4) /// /// If the user agent does attach a Cookie header field to an HTTP /// request, the user agent must send the cookie-string /// as the value of the header field. /// /// When the user agent generates an HTTP request, the user agent MUST NOT /// attach more than one Cookie header field. /// /// # Example values /// * `SID=31d4d96e407aad42` /// * `SID=31d4d96e407aad42; lang=en-US` /// #[derive(Clone, Debug)] pubstruct Cookie(FlatCsv<SemiColon>);
derive_header! {
Cookie(_),
name: COOKIE
}
impl Cookie { /// Lookup a value for a cookie name. /// /// # Example /// /// ``` /// # extern crate headers; /// use headers::{Cookie, HeaderMap, HeaderMapExt, HeaderValue}; /// /// // Setup the header map with strings... /// let mut headers = HeaderMap::new(); /// headers.insert("cookie", HeaderValue::from_static("lang=en-US")); /// /// // Parse a `Cookie` so we can play with it... /// let cookie = headers /// .typed_get::<Cookie>() /// .expect("we just inserted a valid Cookie"); /// /// assert_eq!(cookie.get("lang"), Some("en-US")); /// assert_eq!(cookie.get("SID"), None); /// ``` pubfn get(&self, name: &str) -> Option<&str> { self.iter()
.find(|&(key, _)| key == name)
.map(|(_, val)| val)
}
/// Get the number of key-value pairs this `Cookie` contains. pubfn len(&self) -> usize { self.iter().count()
}
/// Iterator the key-value pairs of this `Cookie` header. pubfn iter(&self) -> impl Iterator<Item = (&str, &str)> { self.0.iter().filter_map(|kv| { letmut iter = kv.splitn(2, '='); let key = iter.next()?.trim(); let val = iter.next()?.trim();
Some((key, val))
})
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.