Basic Cookie and Set-Cookie (only parsing) headers implementation.
This commit is contained in:
committed by
Sean McArthur
parent
b7957ed36c
commit
a85cc476e1
42
src/header/common/set_cookie.rs
Normal file
42
src/header/common/set_cookie.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use header::Header;
|
||||
use std::fmt;
|
||||
use std::str::from_utf8;
|
||||
|
||||
/// The `Set-Cookie` header
|
||||
///
|
||||
/// Informally, the Set-Cookie response header contains the header name
|
||||
/// "Set-Cookie" followed by a ":" and a cookie. Each cookie begins with
|
||||
/// a name-value-pair, followed by zero or more attribute-value pairs.
|
||||
#[deriving(Clone, PartialEq, Show)]
|
||||
pub struct SetCookie(pub Vec<String>);
|
||||
|
||||
impl Header for SetCookie {
|
||||
fn header_name(_: Option<SetCookie>) -> &'static str {
|
||||
"Set-Cookie"
|
||||
}
|
||||
|
||||
fn parse_header(raw: &[Vec<u8>]) -> Option<SetCookie> {
|
||||
let mut set_cookies: Vec<String> = vec![];
|
||||
for set_cookies_raw in raw.iter() {
|
||||
match from_utf8(set_cookies_raw.as_slice()) {
|
||||
Some(set_cookies_str) => {
|
||||
if !set_cookies_str.is_empty() {
|
||||
set_cookies.push(set_cookies_str.to_string());
|
||||
}
|
||||
},
|
||||
None => ()
|
||||
};
|
||||
}
|
||||
|
||||
if !set_cookies.is_empty() {
|
||||
Some(SetCookie(set_cookies))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_header(&self, _: &mut fmt::Formatter) -> fmt::Result {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user