diff --git a/src/header/mod.rs b/src/header/mod.rs index 005ef8b7..b726f879 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -10,8 +10,7 @@ use std::hash; use std::intrinsics::TypeId; use std::mem::{transmute, transmute_copy}; use std::raw::TraitObject; -use std::str::{from_utf8, SendStr, Slice, Owned}; -use std::string::raw; +use std::str::{SendStr, Slice, Owned}; use std::collections::hashmap::{HashMap, Entries, Occupied, Vacant}; use std::sync::RWLock; @@ -95,12 +94,6 @@ impl Headers { loop { match try!(read_header(rdr)) { Some((name, value)) => { - // read_header already checks that name is a token, which - // means its safe utf8 - let name = unsafe { - raw::from_utf8(name) - }; - let name = CaseInsensitive(Owned(name)); let item = match headers.data.entry(name) { Vacant(entry) => entry.set(RWLock::new(Raw(vec![]))), diff --git a/src/http.rs b/src/http.rs index 61e831e3..6faf12ec 100644 --- a/src/http.rs +++ b/src/http.rs @@ -520,9 +520,9 @@ pub fn read_http_version(stream: &mut R) -> HttpResult { /// The raw bytes when parsing a header line. /// -/// 2 vectors of u8s, divided by COLON (`:`). The first vector is guaranteed +/// A String and Vec, divided by COLON (`:`). The String is guaranteed /// to be all `token`s. See `is_token_char` source for all valid characters. -pub type RawHeaderLine = (Vec, Vec); +pub type RawHeaderLine = (String, Vec); /// Read a RawHeaderLine from a Reader. /// @@ -545,7 +545,7 @@ pub type RawHeaderLine = (Vec, Vec); /// > ; see Section 3.2.4 /// > ``` pub fn read_header(stream: &mut R) -> HttpResult> { - let mut name = vec![]; + let mut name = String::new(); let mut value = vec![]; loop { @@ -557,7 +557,7 @@ pub fn read_header(stream: &mut R) -> HttpResult break, - b if is_token(b) => name.push(b), + b if is_token(b) => name.push(b as char), _nontoken => return Err(HttpHeaderError) }; } @@ -745,7 +745,7 @@ mod tests { assert_eq!(read_header(&mut mem(s)), result); } - read("Host: rust-lang.org\r\n", Ok(Some(("Host".as_bytes().to_vec(), + read("Host: rust-lang.org\r\n", Ok(Some(("Host".to_string(), "rust-lang.org".as_bytes().to_vec())))); }