adjust RawHeaderLine to be (String, Vec<u8>)
This commit is contained in:
@@ -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![]))),
|
||||
|
||||
10
src/http.rs
10
src/http.rs
@@ -520,9 +520,9 @@ pub fn read_http_version<R: Reader>(stream: &mut R) -> HttpResult<HttpVersion> {
|
||||
|
||||
/// The raw bytes when parsing a header line.
|
||||
///
|
||||
/// 2 vectors of u8s, divided by COLON (`:`). The first vector is guaranteed
|
||||
/// A String and Vec<u8>, 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<u8>, Vec<u8>);
|
||||
pub type RawHeaderLine = (String, Vec<u8>);
|
||||
|
||||
/// Read a RawHeaderLine from a Reader.
|
||||
///
|
||||
@@ -545,7 +545,7 @@ pub type RawHeaderLine = (Vec<u8>, Vec<u8>);
|
||||
/// > ; see Section 3.2.4
|
||||
/// > ```
|
||||
pub fn read_header<R: Reader>(stream: &mut R) -> HttpResult<Option<RawHeaderLine>> {
|
||||
let mut name = vec![];
|
||||
let mut name = String::new();
|
||||
let mut value = vec![];
|
||||
|
||||
loop {
|
||||
@@ -557,7 +557,7 @@ pub fn read_header<R: Reader>(stream: &mut R) -> HttpResult<Option<RawHeaderLine
|
||||
}
|
||||
},
|
||||
b':' => 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()))));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user