feat(http): use the bytes crate for Chunk and internally

This commit is contained in:
Sean McArthur
2017-03-01 14:14:34 -08:00
parent cf7cc50ad0
commit 65b3e08f69
14 changed files with 306 additions and 598 deletions

View File

@@ -933,7 +933,7 @@ mod tests {
use header::Header;
use http::{ServerTransaction, Http1Transaction};
use http::buf::MemBuf;
use bytes::BytesMut;
use mime::Mime;
use mime::TopLevel::Text;
@@ -1018,7 +1018,7 @@ mod tests {
let expected_link = Link::new(vec![first_link, second_link, third_link]);
let raw = MemBuf::from(b"GET /super_short_uri/and_whatever HTTP/1.1\r\nHost: \
let mut raw = BytesMut::from(b"GET /super_short_uri/and_whatever HTTP/1.1\r\nHost: \
hyper.rs\r\nAccept: a lot of things\r\nAccept-Charset: \
utf8\r\nAccept-Encoding: *\r\nLink: </TheBook/chapter2>; \
rel=\"previous\"; title*=UTF-8'de'letztes%20Kapitel, \
@@ -1029,7 +1029,7 @@ mod tests {
rel=\"previous\"; rev=next; title=\"previous chapter\"\
\r\n\r\n".to_vec());
let (mut res, _) = ServerTransaction::parse(&raw).unwrap().unwrap();
let (mut res, _) = ServerTransaction::parse(&mut raw).unwrap().unwrap();
let link = res.headers.remove::<Link>().unwrap();

View File

@@ -87,7 +87,7 @@ use self::internals::{Item, VecMap, Entry};
pub use self::shared::*;
pub use self::common::*;
pub use self::raw::Raw;
use http::buf::MemSlice;
use bytes::Bytes;
mod common;
mod internals;
@@ -611,8 +611,8 @@ impl<'a> Extend<HeaderView<'a>> for Headers {
}
}
impl<'a> Extend<(&'a str, MemSlice)> for Headers {
fn extend<I: IntoIterator<Item=(&'a str, MemSlice)>>(&mut self, iter: I) {
impl<'a> Extend<(&'a str, Bytes)> for Headers {
fn extend<I: IntoIterator<Item=(&'a str, Bytes)>>(&mut self, iter: I) {
for (name, value) in iter {
let name = HeaderName(UniCase(maybe_literal(name)));
//let trim = header.value.iter().rev().take_while(|&&x| x == b' ').count();

View File

@@ -1,6 +1,6 @@
use std::borrow::Cow;
use std::fmt;
use http::buf::MemSlice;
use bytes::Bytes;
/// A raw header value.
#[derive(Clone, PartialEq, Eq)]
@@ -72,7 +72,7 @@ enum Lines {
enum Line {
Static(&'static [u8]),
Owned(Vec<u8>),
Shared(MemSlice),
Shared(Bytes),
}
fn eq<A: AsRef<[u8]>, B: AsRef<[u8]>>(a: &[A], b: &[B]) -> bool {
@@ -152,9 +152,9 @@ impl<'a> From<&'a [u8]> for Raw {
}
}
impl From<MemSlice> for Raw {
impl From<Bytes> for Raw {
#[inline]
fn from(val: MemSlice) -> Raw {
fn from(val: Bytes) -> Raw {
Raw(Lines::One(Line::Shared(val)))
}
}
@@ -166,9 +166,9 @@ impl From<Vec<u8>> for Line {
}
}
impl From<MemSlice> for Line {
impl From<Bytes> for Line {
#[inline]
fn from(val: MemSlice) -> Line {
fn from(val: Bytes) -> Line {
Line::Shared(val)
}
}
@@ -183,11 +183,11 @@ impl AsRef<[u8]> for Line {
}
}
pub fn parsed(val: MemSlice) -> Raw {
pub fn parsed(val: Bytes) -> Raw {
Raw(Lines::One(From::from(val)))
}
pub fn push(raw: &mut Raw, val: MemSlice) {
pub fn push(raw: &mut Raw, val: Bytes) {
raw.push_line(Line::from(val));
}