Miscellaneous fixes and test updates for all the other changes

- http::LINE_ENDING is now an &'static str
This commit is contained in:
Jonathan Reem
2015-01-06 01:15:47 +01:00
parent 66aa08ecdd
commit 93fcd05b9d
9 changed files with 35 additions and 58 deletions

View File

@@ -5,7 +5,8 @@ use std::cmp::min;
use std::fmt;
use std::io::{self, Reader, IoResult, BufWriter};
use std::num::from_u16;
use std::str::{self, SendStr, FromStr};
use std::str::{self, FromStr};
use std::string::CowString;
use url::Url;
use url::ParseError as UrlError;
@@ -108,7 +109,7 @@ impl<R: Reader> Reader for HttpReader<R> {
*opt_remaining = if rem > 0 {
Some(rem)
} else {
try!(eat(body, LINE_ENDING));
try!(eat(body, LINE_ENDING.as_bytes()));
None
};
Ok(count)
@@ -237,9 +238,9 @@ impl<W: Writer> Writer for HttpWriter<W> {
ChunkedWriter(ref mut w) => {
let chunk_size = msg.len();
debug!("chunked write, size = {}", chunk_size);
try!(write!(w, "{:X}{}{}", chunk_size, CR as char, LF as char));
try!(write!(w, "{:X}{}", chunk_size, LINE_ENDING));
try!(w.write(msg));
w.write(LINE_ENDING)
w.write_str(LINE_ENDING)
},
SizedWriter(ref mut w, ref mut remaining) => {
let len = msg.len();
@@ -283,7 +284,7 @@ pub const SP: u8 = b' ';
pub const CR: u8 = b'\r';
pub const LF: u8 = b'\n';
pub const STAR: u8 = b'*';
pub const LINE_ENDING: &'static [u8] = &[CR, LF];
pub const LINE_ENDING: &'static str = "\r\n";
/// A `Show`able struct to easily write line endings to a formatter.
pub struct LineEnding;
@@ -292,13 +293,7 @@ impl Copy for LineEnding {}
impl fmt::Show for LineEnding {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write(LINE_ENDING)
}
}
impl AsSlice<u8> for LineEnding {
fn as_slice(&self) -> &[u8] {
LINE_ENDING
fmt.write_str(LINE_ENDING)
}
}
@@ -584,7 +579,7 @@ pub type StatusLine = (HttpVersion, RawStatus);
/// The raw status code and reason-phrase.
#[derive(PartialEq, Show)]
pub struct RawStatus(pub u16, pub SendStr);
pub struct RawStatus(pub u16, pub CowString<'static>);
impl Clone for RawStatus {
fn clone(&self) -> RawStatus {