diff --git a/Cargo.toml b/Cargo.toml index bd454cb..3a0cff9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ charset = ["encoding"] tls = ["rustls", "webpki", "webpki-roots"] [dependencies] -ascii = "1" base64 = "0.10" chunked_transfer = "1" cookie = { version = "0.12", features = ["percent-encode"] } diff --git a/src/header.rs b/src/header.rs index 9ebdf88..4c96159 100644 --- a/src/header.rs +++ b/src/header.rs @@ -1,11 +1,10 @@ use crate::error::Error; -use ascii::{AsAsciiStr, AsciiString}; use std::str::FromStr; #[derive(Clone)] /// Wrapper type for a header line. pub struct Header { - line: AsciiString, + line: String, index: usize, } @@ -17,8 +16,7 @@ impl ::std::fmt::Debug for Header { impl Header { pub fn new(name: &str, value: &str) -> Self { - let s = format!("{}: {}", name, value); - let line = unsafe { s.as_ascii_str_unchecked().to_owned() }; + let line = format!("{}: {}", name, value); let index = name.len(); Header { line, index } } @@ -88,7 +86,7 @@ impl FromStr for Header { type Err = Error; fn from_str(s: &str) -> Result { // - let line = AsciiString::from_str(s).map_err(|_| Error::BadHeader)?; + let line = s.to_string(); let index = s.find(':').ok_or_else(|| Error::BadHeader)?; // no value? diff --git a/src/response.rs b/src/response.rs index 910c30f..def046e 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,7 +1,6 @@ use std::io::{Cursor, Error as IoError, ErrorKind, Read, Result as IoResult}; use std::str::FromStr; -use ascii::AsciiString; use chunked_transfer::Decoder as ChunkDecoder; use crate::error::Error; @@ -40,7 +39,7 @@ pub const DEFAULT_CHARACTER_SET: &str = "utf-8"; pub struct Response { url: Option, error: Option, - status_line: AsciiString, + status_line: String, index: (usize, usize), // index into status_line where we split: HTTP/1.1 200 OK status: u16, headers: Vec
, @@ -117,7 +116,7 @@ impl Response { pub fn headers_names(&self) -> Vec { self.headers .iter() - .map(|h| h.name().to_ascii_lowercase()) + .map(|h| h.name().to_lowercase()) .collect() } @@ -513,7 +512,7 @@ pub(crate) fn set_stream(resp: &mut Response, url: String, unit: Option, s resp.stream = Some(stream); } -fn read_next_line(reader: &mut R) -> IoResult { +fn read_next_line(reader: &mut R) -> IoResult { let mut buf = Vec::new(); let mut prev_byte_was_cr = false; @@ -527,7 +526,7 @@ fn read_next_line(reader: &mut R) -> IoResult { if byte == b'\n' && prev_byte_was_cr { buf.pop(); // removing the '\r' - return AsciiString::from_ascii(buf) + return String::from_utf8(buf) .map_err(|_| IoError::new(ErrorKind::InvalidInput, "Header is not in ASCII")); } diff --git a/src/test/simple.rs b/src/test/simple.rs index fe4c2c8..d8e879c 100644 --- a/src/test/simple.rs +++ b/src/test/simple.rs @@ -134,9 +134,10 @@ fn non_ascii_header() { let resp = get("test://host/non_ascii_header") .set("Bäd", "Headör") .call(); - assert!(!resp.ok()); - assert_eq!(resp.status(), 500); - assert_eq!(resp.status_text(), "Bad Header"); + // surprisingly, this is ok, because this lib is not about enforcing standards. + assert!(resp.ok()); + assert_eq!(resp.status(), 200); + assert_eq!(resp.status_text(), "OK"); } #[test]