From 71ac65da5beb1c7dd7238f6be14d9262580ac5ed Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 2 Jun 2015 12:24:56 -0700 Subject: [PATCH] refactor(http): move h1 and h2 into http module --- examples/client_http2.rs | 4 +- src/client/mod.rs | 4 +- src/client/request.rs | 6 +- src/client/response.rs | 7 +- src/{http.rs => http/h1.rs} | 327 ++++++++++++++++++++++++++++++++--- src/{http2.rs => http/h2.rs} | 6 +- src/{ => http}/message.rs | 0 src/http/mod.rs | 28 +++ src/http11.rs | 305 -------------------------------- src/lib.rs | 4 - src/server/request.rs | 6 +- src/server/response.rs | 4 +- 12 files changed, 351 insertions(+), 350 deletions(-) rename src/{http.rs => http/h1.rs} (65%) rename src/{http2.rs => http/h2.rs} (99%) rename src/{ => http}/message.rs (100%) create mode 100644 src/http/mod.rs delete mode 100644 src/http11.rs diff --git a/examples/client_http2.rs b/examples/client_http2.rs index 41f65c19..677dc753 100644 --- a/examples/client_http2.rs +++ b/examples/client_http2.rs @@ -8,7 +8,7 @@ use std::io; use hyper::Client; use hyper::header::Connection; -use hyper::http2; +use hyper::http::h2; fn main() { env_logger::init().unwrap(); @@ -21,7 +21,7 @@ fn main() { } }; - let mut client = Client::with_protocol(http2::new_protocol()); + let mut client = Client::with_protocol(h2::new_protocol()); // `Connection: Close` is not a valid header for HTTP/2, but the client handles it gracefully. let mut res = client.get(&*url) diff --git a/src/client/mod.rs b/src/client/mod.rs index 419e46cb..a8ba789a 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -54,8 +54,8 @@ pub mod pool; pub mod request; pub mod response; -use message::Protocol; -use http11::Http11Protocol; +use http::Protocol; +use http::h1::Http11Protocol; /// A Client to use additional features with Requests. /// diff --git a/src/client/request.rs b/src/client/request.rs index 98db4a66..c6259bc3 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -11,8 +11,8 @@ use net::{NetworkStream, NetworkConnector, HttpConnector, Fresh, Streaming}; use version; use client::{Response, get_host_and_port}; -use message::{HttpMessage, RequestHead}; -use http11::Http11Message; +use http::{HttpMessage, RequestHead}; +use http::h1::Http11Message; /// A client request to a remote server. @@ -136,7 +136,7 @@ mod tests { use header::{ContentLength,TransferEncoding,Encoding}; use url::form_urlencoded; use super::Request; - use http11::Http11Message; + use http::h1::Http11Message; fn run_request(req: Request) -> Vec { let req = req.start().unwrap(); diff --git a/src/client/response.rs b/src/client/response.rs index 458c7005..5e7522c9 100644 --- a/src/client/response.rs +++ b/src/client/response.rs @@ -3,11 +3,10 @@ use std::io::{self, Read}; use header; use net::NetworkStream; -use http::{self, RawStatus}; +use http::{self, RawStatus, ResponseHead, HttpMessage}; use status; use version; -use message::{ResponseHead, HttpMessage}; -use http11::Http11Message; +use http::h1::Http11Message; /// A response for a client request to a remote server. #[derive(Debug)] @@ -82,7 +81,7 @@ mod tests { use mock::MockStream; use status; use version; - use http11::Http11Message; + use http::h1::Http11Message; use super::Response; diff --git a/src/http.rs b/src/http/h1.rs similarity index 65% rename from src/http.rs rename to src/http/h1.rs index 71068278..babe15d2 100644 --- a/src/http.rs +++ b/src/http/h1.rs @@ -1,22 +1,318 @@ -//! Pieces pertaining to the HTTP message protocol. -use std::borrow::{Cow, ToOwned}; +//! Adapts the HTTP/1.1 implementation into the `HttpMessage` API. +use std::borrow::Cow; use std::cmp::min; -use std::io::{self, Read, Write, BufRead}; use std::fmt; +use std::io::{self, Write, BufWriter, BufRead, Read}; +use std::net::Shutdown; use httparse; use buffer::BufReader; -use header::{Headers, Connection}; -use header::ConnectionOption::{Close, KeepAlive}; -use method::Method; +use Error; +use header::{Headers, ContentLength, TransferEncoding}; +use header::Encoding::Chunked; +use method::{Method}; +use net::{NetworkConnector, NetworkStream, ContextVerifier}; use status::StatusCode; +use version::HttpVersion; +use version::HttpVersion::{Http10, Http11}; use uri::RequestUri; -use version::HttpVersion::{self, Http10, Http11}; -use {Error}; use self::HttpReader::{SizedReader, ChunkedReader, EofReader, EmptyReader}; -use self::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter, EmptyWriter}; +use self::HttpWriter::{ChunkedWriter, SizedWriter, EmptyWriter, ThroughWriter}; + +use http::{ + RawStatus, + Protocol, + HttpMessage, + RequestHead, + ResponseHead, +}; +use header; +use version; + +/// An implementation of the `HttpMessage` trait for HTTP/1.1. +#[derive(Debug)] +pub struct Http11Message { + stream: Option>, + writer: Option>>>, + reader: Option>>>, +} + +impl Write for Http11Message { + #[inline] + fn write(&mut self, buf: &[u8]) -> io::Result { + match self.writer { + None => Err(io::Error::new(io::ErrorKind::Other, + "Not in a writable state")), + Some(ref mut writer) => writer.write(buf), + } + } + #[inline] + fn flush(&mut self) -> io::Result<()> { + match self.writer { + None => Err(io::Error::new(io::ErrorKind::Other, + "Not in a writable state")), + Some(ref mut writer) => writer.flush(), + } + } +} + +impl Read for Http11Message { + #[inline] + fn read(&mut self, buf: &mut [u8]) -> io::Result { + match self.reader { + None => Err(io::Error::new(io::ErrorKind::Other, + "Not in a readable state")), + Some(ref mut reader) => reader.read(buf), + } + } +} + +impl HttpMessage for Http11Message { + fn set_outgoing(&mut self, mut head: RequestHead) -> ::Result { + if self.stream.is_none() { + return Err(From::from(io::Error::new( + io::ErrorKind::Other, + "Message not idle, cannot start new outgoing"))); + } + let mut stream = BufWriter::new(self.stream.take().unwrap()); + + let mut uri = head.url.serialize_path().unwrap(); + if let Some(ref q) = head.url.query { + uri.push('?'); + uri.push_str(&q[..]); + } + + let version = version::HttpVersion::Http11; + debug!("request line: {:?} {:?} {:?}", head.method, uri, version); + try!(write!(&mut stream, "{} {} {}{}", + head.method, uri, version, LINE_ENDING)); + + let stream = match head.method { + Method::Get | Method::Head => { + debug!("headers={:?}", head.headers); + try!(write!(&mut stream, "{}{}", head.headers, LINE_ENDING)); + EmptyWriter(stream) + }, + _ => { + let mut chunked = true; + let mut len = 0; + + match head.headers.get::() { + Some(cl) => { + chunked = false; + len = **cl; + }, + None => () + }; + + // can't do in match above, thanks borrowck + if chunked { + let encodings = match head.headers.get_mut::() { + Some(&mut header::TransferEncoding(ref mut encodings)) => { + //TODO: check if chunked is already in encodings. use HashSet? + encodings.push(header::Encoding::Chunked); + false + }, + None => true + }; + + if encodings { + head.headers.set::( + header::TransferEncoding(vec![header::Encoding::Chunked])) + } + } + + debug!("headers={:?}", head.headers); + try!(write!(&mut stream, "{}{}", head.headers, LINE_ENDING)); + + if chunked { + ChunkedWriter(stream) + } else { + SizedWriter(stream, len) + } + } + }; + + self.writer = Some(stream); + + Ok(head) + } + + fn get_incoming(&mut self) -> ::Result { + try!(self.flush_outgoing()); + if self.stream.is_none() { + // The message was already in the reading state... + // TODO Decide what happens in case we try to get a new incoming at that point + return Err(From::from( + io::Error::new(io::ErrorKind::Other, + "Read already in progress"))); + } + + let stream = self.stream.take().unwrap(); + let mut stream = BufReader::new(stream); + + let head = try!(parse_response(&mut stream)); + let raw_status = head.subject; + let headers = head.headers; + + let body = if headers.has::() { + match headers.get::() { + Some(&TransferEncoding(ref codings)) => { + if codings.len() > 1 { + trace!("TODO: #2 handle other codings: {:?}", codings); + }; + + if codings.contains(&Chunked) { + ChunkedReader(stream, None) + } else { + trace!("not chuncked. read till eof"); + EofReader(stream) + } + } + None => unreachable!() + } + } else if headers.has::() { + match headers.get::() { + Some(&ContentLength(len)) => SizedReader(stream, len), + None => unreachable!() + } + } else { + trace!("neither Transfer-Encoding nor Content-Length"); + EofReader(stream) + }; + + self.reader = Some(body); + + Ok(ResponseHead { + headers: headers, + raw_status: raw_status, + version: head.version, + }) + } + + fn close_connection(&mut self) -> ::Result<()> { + try!(self.get_mut().close(Shutdown::Both)); + Ok(()) + } +} + +impl Http11Message { + /// Consumes the `Http11Message` and returns the underlying `NetworkStream`. + pub fn into_inner(mut self) -> Box { + if self.stream.is_some() { + self.stream.take().unwrap() + } else if self.writer.is_some() { + self.writer.take().unwrap().into_inner().into_inner().unwrap() + } else if self.reader.is_some() { + self.reader.take().unwrap().into_inner().into_inner() + } else { + panic!("Http11Message lost its underlying stream somehow"); + } + } + + /// Gets a mutable reference to the underlying `NetworkStream`, regardless of the state of the + /// `Http11Message`. + pub fn get_mut(&mut self) -> &mut Box { + if self.stream.is_some() { + self.stream.as_mut().unwrap() + } else if self.writer.is_some() { + self.writer.as_mut().unwrap().get_mut().get_mut() + } else if self.reader.is_some() { + self.reader.as_mut().unwrap().get_mut().get_mut() + } else { + panic!("Http11Message lost its underlying stream somehow"); + } + } + + /// Creates a new `Http11Message` that will use the given `NetworkStream` for communicating to + /// the peer. + pub fn with_stream(stream: Box) -> Http11Message { + Http11Message { + stream: Some(stream), + writer: None, + reader: None, + } + } + + /// Flushes the current outgoing content and moves the stream into the `stream` property. + /// + /// TODO It might be sensible to lift this up to the `HttpMessage` trait itself... + pub fn flush_outgoing(&mut self) -> ::Result<()> { + match self.writer { + None => return Ok(()), + Some(_) => {}, + }; + + let writer = self.writer.take().unwrap(); + let raw = try!(writer.end()).into_inner().unwrap(); // end() already flushes + self.stream = Some(raw); + + Ok(()) + } +} + +/// The `Protocol` implementation provides HTTP/1.1 messages. +pub struct Http11Protocol { + connector: Connector, +} + +impl Protocol for Http11Protocol { + fn new_message(&self, host: &str, port: u16, scheme: &str) -> ::Result> { + let stream = try!(self.connector.connect(host, port, scheme)).into(); + + Ok(Box::new(Http11Message::with_stream(stream))) + } + + #[inline] + fn set_ssl_verifier(&mut self, verifier: ContextVerifier) { + self.connector.set_ssl_verifier(verifier); + } +} + +impl Http11Protocol { + /// Creates a new `Http11Protocol` instance that will use the given `NetworkConnector` for + /// establishing HTTP connections. + pub fn with_connector(c: C) -> Http11Protocol + where C: NetworkConnector + Send + 'static, + S: NetworkStream + Send { + Http11Protocol { + connector: Connector(Box::new(ConnAdapter(c))), + } + } +} + +struct ConnAdapter(C); + +impl + Send, S: NetworkStream + Send> NetworkConnector for ConnAdapter { + type Stream = Box; + #[inline] + fn connect(&self, host: &str, port: u16, scheme: &str) + -> ::Result> { + Ok(try!(self.0.connect(host, port, scheme)).into()) + } + #[inline] + fn set_ssl_verifier(&mut self, verifier: ContextVerifier) { + self.0.set_ssl_verifier(verifier); + } +} + +struct Connector(Box> + Send>); + +impl NetworkConnector for Connector { + type Stream = Box; + #[inline] + fn connect(&self, host: &str, port: u16, scheme: &str) + -> ::Result> { + Ok(try!(self.0.connect(host, port, scheme)).into()) + } + #[inline] + fn set_ssl_verifier(&mut self, verifier: ContextVerifier) { + self.0.set_ssl_verifier(verifier); + } +} + /// Readers to handle different Transfer-Encodings. /// @@ -451,19 +747,6 @@ pub const LF: u8 = b'\n'; pub const STAR: u8 = b'*'; pub const LINE_ENDING: &'static str = "\r\n"; -/// The raw status code and reason-phrase. -#[derive(Clone, PartialEq, Debug)] -pub struct RawStatus(pub u16, pub Cow<'static, str>); - -/// Checks if a connection should be kept alive. -pub fn should_keep_alive(version: HttpVersion, headers: &Headers) -> bool { - match (version, headers.get::()) { - (Http10, Some(conn)) if !conn.contains(&KeepAlive) => false, - (Http11, Some(conn)) if conn.contains(&Close) => false, - _ => true - } -} - #[cfg(test)] mod tests { use std::io::{self, Write}; diff --git a/src/http2.rs b/src/http/h2.rs similarity index 99% rename from src/http2.rs rename to src/http/h2.rs index bd75dad3..0e7fd89e 100644 --- a/src/http2.rs +++ b/src/http/h2.rs @@ -5,16 +5,16 @@ use std::net::Shutdown; use std::ascii::AsciiExt; use std::mem; -use message::{ +use http::{ Protocol, HttpMessage, RequestHead, ResponseHead, + RawStatus, }; use net::{NetworkStream, NetworkConnector, ContextVerifier}; use net::{HttpConnector, HttpStream}; use url::Url; -use http::RawStatus; use header::Headers; use header; @@ -397,7 +397,7 @@ mod tests { use std::io::{Read}; use mock::{MockHttp2Connector, MockStream}; - use message::{RequestHead, ResponseHead, Protocol}; + use http::{RequestHead, ResponseHead, Protocol}; use header::Headers; use header; diff --git a/src/message.rs b/src/http/message.rs similarity index 100% rename from src/message.rs rename to src/http/message.rs diff --git a/src/http/mod.rs b/src/http/mod.rs new file mode 100644 index 00000000..6571f073 --- /dev/null +++ b/src/http/mod.rs @@ -0,0 +1,28 @@ +//! Pieces pertaining to the HTTP message protocol. +use std::borrow::Cow; + +use header::Connection; +use header::ConnectionOption::{KeepAlive, Close}; +use header::Headers; +use version::HttpVersion; +use version::HttpVersion::{Http10, Http11}; + +pub use self::message::{HttpMessage, RequestHead, ResponseHead, Protocol}; + +pub mod h1; +pub mod h2; +pub mod message; + +/// The raw status code and reason-phrase. +#[derive(Clone, PartialEq, Debug)] +pub struct RawStatus(pub u16, pub Cow<'static, str>); + +/// Checks if a connection should be kept alive. +#[inline] +pub fn should_keep_alive(version: HttpVersion, headers: &Headers) -> bool { + match (version, headers.get::()) { + (Http10, Some(conn)) if !conn.contains(&KeepAlive) => false, + (Http11, Some(conn)) if conn.contains(&Close) => false, + _ => true + } +} diff --git a/src/http11.rs b/src/http11.rs deleted file mode 100644 index d1a704bc..00000000 --- a/src/http11.rs +++ /dev/null @@ -1,305 +0,0 @@ -//! Adapts the HTTP/1.1 implementation into the `HttpMessage` API. -use std::io::{self, Write, BufWriter, Read}; -use std::net::Shutdown; - -use method::{Method}; -use header::{ContentLength, TransferEncoding}; -use header::Encoding::Chunked; - -use net::{NetworkConnector, NetworkStream, ContextVerifier}; -use http::{HttpWriter, LINE_ENDING}; -use http::HttpReader::{SizedReader, ChunkedReader, EofReader}; -use http::HttpWriter::{ChunkedWriter, SizedWriter, EmptyWriter}; -use buffer::BufReader; -use http::{self, HttpReader}; - -use message::{ - Protocol, - HttpMessage, - RequestHead, - ResponseHead, -}; -use header; -use version; - -/// An implementation of the `HttpMessage` trait for HTTP/1.1. -#[derive(Debug)] -pub struct Http11Message { - stream: Option>, - writer: Option>>>, - reader: Option>>>, -} - -impl Write for Http11Message { - #[inline] - fn write(&mut self, buf: &[u8]) -> io::Result { - match self.writer { - None => Err(io::Error::new(io::ErrorKind::Other, - "Not in a writable state")), - Some(ref mut writer) => writer.write(buf), - } - } - #[inline] - fn flush(&mut self) -> io::Result<()> { - match self.writer { - None => Err(io::Error::new(io::ErrorKind::Other, - "Not in a writable state")), - Some(ref mut writer) => writer.flush(), - } - } -} - -impl Read for Http11Message { - #[inline] - fn read(&mut self, buf: &mut [u8]) -> io::Result { - match self.reader { - None => Err(io::Error::new(io::ErrorKind::Other, - "Not in a readable state")), - Some(ref mut reader) => reader.read(buf), - } - } -} - -impl HttpMessage for Http11Message { - fn set_outgoing(&mut self, mut head: RequestHead) -> ::Result { - if self.stream.is_none() { - return Err(From::from(io::Error::new( - io::ErrorKind::Other, - "Message not idle, cannot start new outgoing"))); - } - let mut stream = BufWriter::new(self.stream.take().unwrap()); - - let mut uri = head.url.serialize_path().unwrap(); - if let Some(ref q) = head.url.query { - uri.push('?'); - uri.push_str(&q[..]); - } - - let version = version::HttpVersion::Http11; - debug!("request line: {:?} {:?} {:?}", head.method, uri, version); - try!(write!(&mut stream, "{} {} {}{}", - head.method, uri, version, LINE_ENDING)); - - let stream = match head.method { - Method::Get | Method::Head => { - debug!("headers={:?}", head.headers); - try!(write!(&mut stream, "{}{}", head.headers, LINE_ENDING)); - EmptyWriter(stream) - }, - _ => { - let mut chunked = true; - let mut len = 0; - - match head.headers.get::() { - Some(cl) => { - chunked = false; - len = **cl; - }, - None => () - }; - - // can't do in match above, thanks borrowck - if chunked { - let encodings = match head.headers.get_mut::() { - Some(&mut header::TransferEncoding(ref mut encodings)) => { - //TODO: check if chunked is already in encodings. use HashSet? - encodings.push(header::Encoding::Chunked); - false - }, - None => true - }; - - if encodings { - head.headers.set::( - header::TransferEncoding(vec![header::Encoding::Chunked])) - } - } - - debug!("headers={:?}", head.headers); - try!(write!(&mut stream, "{}{}", head.headers, LINE_ENDING)); - - if chunked { - ChunkedWriter(stream) - } else { - SizedWriter(stream, len) - } - } - }; - - self.writer = Some(stream); - - Ok(head) - } - - fn get_incoming(&mut self) -> ::Result { - try!(self.flush_outgoing()); - if self.stream.is_none() { - // The message was already in the reading state... - // TODO Decide what happens in case we try to get a new incoming at that point - return Err(From::from( - io::Error::new(io::ErrorKind::Other, - "Read already in progress"))); - } - - let stream = self.stream.take().unwrap(); - let mut stream = BufReader::new(stream); - - let head = try!(http::parse_response(&mut stream)); - let raw_status = head.subject; - let headers = head.headers; - - let body = if headers.has::() { - match headers.get::() { - Some(&TransferEncoding(ref codings)) => { - if codings.len() > 1 { - trace!("TODO: #2 handle other codings: {:?}", codings); - }; - - if codings.contains(&Chunked) { - ChunkedReader(stream, None) - } else { - trace!("not chuncked. read till eof"); - EofReader(stream) - } - } - None => unreachable!() - } - } else if headers.has::() { - match headers.get::() { - Some(&ContentLength(len)) => SizedReader(stream, len), - None => unreachable!() - } - } else { - trace!("neither Transfer-Encoding nor Content-Length"); - EofReader(stream) - }; - - self.reader = Some(body); - - Ok(ResponseHead { - headers: headers, - raw_status: raw_status, - version: head.version, - }) - } - - fn close_connection(&mut self) -> ::Result<()> { - try!(self.get_mut().close(Shutdown::Both)); - Ok(()) - } -} - -impl Http11Message { - /// Consumes the `Http11Message` and returns the underlying `NetworkStream`. - pub fn into_inner(mut self) -> Box { - if self.stream.is_some() { - self.stream.take().unwrap() - } else if self.writer.is_some() { - self.writer.take().unwrap().into_inner().into_inner().unwrap() - } else if self.reader.is_some() { - self.reader.take().unwrap().into_inner().into_inner() - } else { - panic!("Http11Message lost its underlying stream somehow"); - } - } - - /// Gets a mutable reference to the underlying `NetworkStream`, regardless of the state of the - /// `Http11Message`. - pub fn get_mut(&mut self) -> &mut Box { - if self.stream.is_some() { - self.stream.as_mut().unwrap() - } else if self.writer.is_some() { - self.writer.as_mut().unwrap().get_mut().get_mut() - } else if self.reader.is_some() { - self.reader.as_mut().unwrap().get_mut().get_mut() - } else { - panic!("Http11Message lost its underlying stream somehow"); - } - } - - /// Creates a new `Http11Message` that will use the given `NetworkStream` for communicating to - /// the peer. - pub fn with_stream(stream: Box) -> Http11Message { - Http11Message { - stream: Some(stream), - writer: None, - reader: None, - } - } - - /// Flushes the current outgoing content and moves the stream into the `stream` property. - /// - /// TODO It might be sensible to lift this up to the `HttpMessage` trait itself... - pub fn flush_outgoing(&mut self) -> ::Result<()> { - match self.writer { - None => return Ok(()), - Some(_) => {}, - }; - - let writer = self.writer.take().unwrap(); - let raw = try!(writer.end()).into_inner().unwrap(); // end() already flushes - self.stream = Some(raw); - - Ok(()) - } -} - -/// The `Protocol` implementation provides HTTP/1.1 messages. -pub struct Http11Protocol { - connector: Connector, -} - -impl Protocol for Http11Protocol { - fn new_message(&self, host: &str, port: u16, scheme: &str) -> ::Result> { - let stream = try!(self.connector.connect(host, port, scheme)).into(); - - Ok(Box::new(Http11Message::with_stream(stream))) - } - - #[inline] - fn set_ssl_verifier(&mut self, verifier: ContextVerifier) { - self.connector.set_ssl_verifier(verifier); - } -} - -impl Http11Protocol { - /// Creates a new `Http11Protocol` instance that will use the given `NetworkConnector` for - /// establishing HTTP connections. - pub fn with_connector(c: C) -> Http11Protocol - where C: NetworkConnector + Send + 'static, - S: NetworkStream + Send { - Http11Protocol { - connector: Connector(Box::new(ConnAdapter(c))), - } - } -} - -struct ConnAdapter(C); - -impl + Send, S: NetworkStream + Send> NetworkConnector for ConnAdapter { - type Stream = Box; - #[inline] - fn connect(&self, host: &str, port: u16, scheme: &str) - -> ::Result> { - Ok(try!(self.0.connect(host, port, scheme)).into()) - } - #[inline] - fn set_ssl_verifier(&mut self, verifier: ContextVerifier) { - self.0.set_ssl_verifier(verifier); - } -} - -struct Connector(Box> + Send>); - -impl NetworkConnector for Connector { - type Stream = Box; - #[inline] - fn connect(&self, host: &str, port: u16, scheme: &str) - -> ::Result> { - Ok(try!(self.0.connect(host, port, scheme)).into()) - } - #[inline] - fn set_ssl_verifier(&mut self, verifier: ContextVerifier) { - self.0.set_ssl_verifier(verifier); - } -} diff --git a/src/lib.rs b/src/lib.rs index 435f101e..5d12dbbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -186,10 +186,6 @@ pub mod server; pub mod status; pub mod uri; pub mod version; -pub mod message; -pub mod http11; -pub mod http2; - /// Re-exporting the mime crate, for convenience. pub mod mime { diff --git a/src/server/request.rs b/src/server/request.rs index 97242007..48fcdea3 100644 --- a/src/server/request.rs +++ b/src/server/request.rs @@ -10,8 +10,8 @@ use net::NetworkStream; use version::{HttpVersion}; use method::Method::{self, Get, Head}; use header::{Headers, ContentLength, TransferEncoding}; -use http::{self, Incoming, HttpReader}; -use http::HttpReader::{SizedReader, ChunkedReader, EmptyReader}; +use http::h1::{self, Incoming, HttpReader}; +use http::h1::HttpReader::{SizedReader, ChunkedReader, EmptyReader}; use uri::RequestUri; /// A request bundles several parts of an incoming `NetworkStream`, given to a `Handler`. @@ -36,7 +36,7 @@ impl<'a, 'b: 'a> Request<'a, 'b> { pub fn new(mut stream: &'a mut BufReader<&'b mut NetworkStream>, addr: SocketAddr) -> ::Result> { - let Incoming { version, subject: (method, uri), headers } = try!(http::parse_request(stream)); + let Incoming { version, subject: (method, uri), headers } = try!(h1::parse_request(stream)); debug!("Request Line: {:?} {:?} {:?}", method, uri, version); debug!("{:?}", headers); diff --git a/src/server/response.rs b/src/server/response.rs index ad6ab692..9c8d43a8 100644 --- a/src/server/response.rs +++ b/src/server/response.rs @@ -11,8 +11,8 @@ use std::ptr; use time::now_utc; use header; -use http::{CR, LF, LINE_ENDING, HttpWriter}; -use http::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter}; +use http::h1::{CR, LF, LINE_ENDING, HttpWriter}; +use http::h1::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter}; use status; use net::{Fresh, Streaming}; use version;