diff --git a/lib/src/data/data.rs b/lib/src/data/data.rs index b892ea42..00a6aae7 100644 --- a/lib/src/data/data.rs +++ b/lib/src/data/data.rs @@ -7,9 +7,14 @@ use std::mem::transmute; use super::data_stream::{DataStream, StreamReader, kill_stream}; use ext::ReadExt; -use http::hyper::{HyperBodyReader, HyperHttpStream}; -use http::hyper::HyperNetworkStream; -use http::hyper::HyperHttpReader::*; + +use http::hyper::h1::HttpReader; +use http::hyper::buffer; +use http::hyper::h1::HttpReader::*; +use http::hyper::net::{HttpStream, NetworkStream}; + +pub type BodyReader<'a, 'b> = + self::HttpReader<&'a mut self::buffer::BufReader<&'b mut NetworkStream>>; /// Type representing the data in the body of an incoming request. /// @@ -76,12 +81,12 @@ impl Data { } #[doc(hidden)] - pub fn from_hyp(mut h_body: HyperBodyReader) -> Result { + pub fn from_hyp(mut h_body: BodyReader) -> Result { // FIXME: This is asolutely terrible, thanks to Hyper. // Retrieve the underlying HTTPStream from Hyper. let mut stream = match h_body.get_ref().get_ref() - .downcast_ref::() { + .downcast_ref::() { Some(s) => { let owned_stream = s.clone(); let buf_len = h_body.get_ref().get_buf().len() as u64; diff --git a/lib/src/data/data_stream.rs b/lib/src/data/data_stream.rs index a04e485a..b44a0399 100644 --- a/lib/src/data/data_stream.rs +++ b/lib/src/data/data_stream.rs @@ -1,15 +1,15 @@ use std::io::{self, BufRead, Read, Cursor, BufReader, Chain, Take}; use std::net::Shutdown; -use http::hyper::{HyperHttpStream, HyperHttpReader}; -use http::hyper::HyperNetworkStream; +use http::hyper::net::{HttpStream, NetworkStream}; +use http::hyper::h1::HttpReader; -pub type StreamReader = HyperHttpReader; +pub type StreamReader = HttpReader; pub type InnerStream = Chain>>, BufReader>; pub struct DataStream { pub stream: InnerStream, - pub network: HyperHttpStream, + pub network: HttpStream, } impl Read for DataStream { @@ -28,7 +28,7 @@ impl BufRead for DataStream { } } -pub fn kill_stream(stream: &mut S, network: &mut N) { +pub fn kill_stream(stream: &mut S, network: &mut N) { io::copy(&mut stream.take(1024), &mut io::sink()).expect("sink"); // If there are any more bytes, kill it. diff --git a/lib/src/data/test_data.rs b/lib/src/data/test_data.rs index ebeac66e..6a0802e4 100644 --- a/lib/src/data/test_data.rs +++ b/lib/src/data/test_data.rs @@ -2,7 +2,12 @@ use std::io::{self, BufRead, Write, Cursor, BufReader}; use std::path::Path; use std::fs::File; -use http::hyper::HyperBodyReader; +use http::hyper::h1::HttpReader; +use http::hyper::net::NetworkStream; +use http::hyper::buffer; + +pub type BodyReader<'a, 'b> = + self::HttpReader<&'a mut self::buffer::BufReader<&'b mut NetworkStream>>; const PEEK_BYTES: usize = 4096; @@ -36,7 +41,7 @@ impl Data { } #[doc(hidden)] - pub fn from_hyp(mut h_body: HyperBodyReader) -> Result { + pub fn from_hyp(mut h_body: BodyReader) -> Result { let mut vec = Vec::new(); if let Err(_) = io::copy(&mut h_body, &mut vec) { return Err("Reading from body failed."); diff --git a/lib/src/http/content_type.rs b/lib/src/http/content_type.rs index bbd27249..da7a9602 100644 --- a/lib/src/http/content_type.rs +++ b/lib/src/http/content_type.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use std::fmt; use http::Header; -use http::mime::Mime; +use http::hyper::mime::Mime; use router::Collider; /// Typed representation of HTTP Content-Types. @@ -236,7 +236,6 @@ impl FromStr for ContentType { /// ```rust /// use std::str::FromStr; /// use rocket::http::ContentType; - /// use rocket::http::mime::{TopLevel, SubLevel}; /// /// let custom = ContentType::from_str("application/x-custom").unwrap(); /// assert!(!custom.is_known()); diff --git a/lib/src/http/cookies.rs b/lib/src/http/cookies.rs index af84b45d..c917d2fb 100644 --- a/lib/src/http/cookies.rs +++ b/lib/src/http/cookies.rs @@ -1,4 +1,5 @@ -pub use http::hyper::HyperCookiePair as Cookie; - use http; -pub type Cookies = http::hyper::HyperCookieJar<'static>; + +pub use http::hyper::header::CookiePair as Cookie; + +pub type Cookies = http::hyper::header::CookieJar<'static>; diff --git a/lib/src/http/hyper.rs b/lib/src/http/hyper.rs index 74a9aa91..bde806b1 100644 --- a/lib/src/http/hyper.rs +++ b/lib/src/http/hyper.rs @@ -7,32 +7,21 @@ //! while necessary. // TODO: Remove from Rocket in favor of a more flexible HTTP library. -pub use hyper::server::Request as HyperRequest; -pub use hyper::server::Response as HyperResponse; -pub use hyper::server::Server as HyperServer; -pub use hyper::server::Handler as HyperHandler; +pub use hyper::server::Request as Request; +pub use hyper::server::Response as Response; +pub use hyper::server::Server as Server; +pub use hyper::server::Handler as Handler; -pub use hyper::header::Headers as HyperHeaders; -pub use hyper::header::CookiePair as HyperCookiePair; -pub use hyper::header::CookieJar as HyperCookieJar; -pub use hyper::header::Cookie as HyperCookie; -pub use hyper::header::SetCookie as HyperSetCookie; - -pub use hyper::method::Method as HyperMethod; -pub use hyper::uri::RequestUri as HyperRequestUri; -pub use hyper::net::Fresh as HyperFresh; -pub use hyper::net::HttpStream as HyperHttpStream; -pub use hyper::net::NetworkStream as HyperNetworkStream; -pub use hyper::http::h1::HttpReader as HyperHttpReader; pub use hyper::header; +pub use hyper::mime; +pub use hyper::net; +pub use hyper::method::Method; pub use hyper::status::StatusCode; +pub use hyper::uri::RequestUri; +pub use hyper::http::h1; +pub use hyper::buffer; // TODO: Remove from Rocket in favor of a more flexible HTTP library. -pub type FreshHyperResponse<'a> = self::HyperResponse<'a, self::HyperFresh>; - -// TODO: Remove from Rocket in favor of a more flexible HTTP library. -use hyper::buffer::BufReader; -pub type HyperBodyReader<'a, 'b> = - HyperHttpReader<&'a mut BufReader<&'b mut HyperNetworkStream>>; +pub type FreshResponse<'a> = self::Response<'a, self::net::Fresh>; diff --git a/lib/src/http/method.rs b/lib/src/http/method.rs index a7035547..407d6c30 100644 --- a/lib/src/http/method.rs +++ b/lib/src/http/method.rs @@ -2,7 +2,7 @@ use std::fmt; use std::str::FromStr; use error::Error; -use http::hyper::HyperMethod; +use http::hyper; use self::Method::*; // TODO: Support non-standard methods, here and in codegen. @@ -23,24 +23,24 @@ pub enum Method { impl Method { #[doc(hidden)] - pub fn from_hyp(method: &HyperMethod) -> Option { + pub fn from_hyp(method: &hyper::Method) -> Option { match *method { - HyperMethod::Get => Some(Get), - HyperMethod::Put => Some(Put), - HyperMethod::Post => Some(Post), - HyperMethod::Delete => Some(Delete), - HyperMethod::Options => Some(Options), - HyperMethod::Head => Some(Head), - HyperMethod::Trace => Some(Trace), - HyperMethod::Connect => Some(Connect), - HyperMethod::Patch => Some(Patch), - HyperMethod::Extension(_) => None, + hyper::Method::Get => Some(Get), + hyper::Method::Put => Some(Put), + hyper::Method::Post => Some(Post), + hyper::Method::Delete => Some(Delete), + hyper::Method::Options => Some(Options), + hyper::Method::Head => Some(Head), + hyper::Method::Trace => Some(Trace), + hyper::Method::Connect => Some(Connect), + hyper::Method::Patch => Some(Patch), + hyper::Method::Extension(_) => None, } } #[doc(hidden)] #[inline(always)] - pub fn to_hyp(&self) -> HyperMethod { + pub fn to_hyp(&self) -> hyper::Method { self.to_string().as_str().parse().unwrap() } diff --git a/lib/src/http/mod.rs b/lib/src/http/mod.rs index 962af220..8ba88f6c 100644 --- a/lib/src/http/mod.rs +++ b/lib/src/http/mod.rs @@ -14,9 +14,6 @@ mod content_type; mod status; mod header; -// TODO: Removed from Rocket in favor of a more flexible HTTP library. -pub use hyper::mime; - pub use self::method::Method; pub use self::content_type::ContentType; pub use self::status::Status; diff --git a/lib/src/request/request.rs b/lib/src/request/request.rs index 1b4e2dde..4867753c 100644 --- a/lib/src/request/request.rs +++ b/lib/src/request/request.rs @@ -9,7 +9,7 @@ use super::{FromParam, FromSegments}; use router::Route; use http::uri::{URI, URIBuf, Segments}; -use http::hyper::{header, HyperCookie, HyperHeaders, HyperMethod, HyperRequestUri}; +use http::hyper::{self, header}; use http::{Method, ContentType, Cookies}; /// The type of an incoming web request. @@ -25,7 +25,7 @@ pub struct Request { uri: URIBuf, // FIXME: Should be URI (without hyper). params: RefCell>, cookies: Cookies, - headers: HyperHeaders, // Don't use hyper's headers. + headers: header::Headers, // Don't use hyper's headers. } impl Request { @@ -106,7 +106,7 @@ impl Request { method: method, cookies: Cookies::new(&[]), uri: URIBuf::from(uri), - headers: HyperHeaders::new(), + headers: header::Headers::new(), } } @@ -120,7 +120,7 @@ impl Request { /// /// Returns the headers in this request. #[inline(always)] - pub fn headers(&self) -> &HyperHeaders { + pub fn headers(&self) -> &header::Headers { // FIXME: Get rid of Hyper. &self.headers } @@ -188,8 +188,8 @@ impl Request { #[doc(hidden)] #[inline(always)] - pub fn set_headers(&mut self, h_headers: HyperHeaders) { - let cookies = match h_headers.get::() { + pub fn set_headers(&mut self, h_headers: header::Headers) { + let cookies = match h_headers.get::() { // TODO: Retrieve key from config. Some(cookie) => cookie.to_cookie_jar(&[]), None => Cookies::new(&[]), @@ -200,12 +200,12 @@ impl Request { } #[doc(hidden)] - pub fn new(h_method: HyperMethod, - h_headers: HyperHeaders, - h_uri: HyperRequestUri) + pub fn new(h_method: hyper::Method, + h_headers: header::Headers, + h_uri: hyper::RequestUri) -> Result { let uri = match h_uri { - HyperRequestUri::AbsolutePath(s) => URIBuf::from(s), + hyper::RequestUri::AbsolutePath(s) => URIBuf::from(s), _ => return Err(format!("Bad URI: {}", h_uri)), }; @@ -214,7 +214,7 @@ impl Request { _ => return Err(format!("Bad method: {}", h_method)), }; - let cookies = match h_headers.get::() { + let cookies = match h_headers.get::() { // TODO: Retrieve key from config. Some(cookie) => cookie.to_cookie_jar(&[]), None => Cookies::new(&[]), diff --git a/lib/src/response/flash.rs b/lib/src/response/flash.rs index 4d33c15d..1a2e5a14 100644 --- a/lib/src/response/flash.rs +++ b/lib/src/response/flash.rs @@ -3,7 +3,7 @@ use std::convert::AsRef; use outcome::IntoOutcome; use response::{Response, Responder}; use request::{self, Request, FromRequest}; -use http::hyper::{HyperSetCookie, HyperCookiePair}; +use http::hyper::header; use http::Status; // The name of the actual flash cookie. @@ -161,9 +161,9 @@ impl<'r, R: Responder<'r>> Flash { Flash::new(responder, "error", msg) } - fn cookie_pair(&self) -> HyperCookiePair { + fn cookie_pair(&self) -> header::CookiePair { let content = format!("{}{}{}", self.name.len(), self.name, self.message); - let mut pair = HyperCookiePair::new(FLASH_COOKIE_NAME.to_string(), content); + let mut pair = header::CookiePair::new(FLASH_COOKIE_NAME.to_string(), content); pair.path = Some("/".to_string()); pair.max_age = Some(300); pair @@ -179,7 +179,7 @@ impl<'r, R: Responder<'r>> Responder<'r> for Flash { trace_!("Flash: setting message: {}:{}", self.name, self.message); let cookie = vec![self.cookie_pair()]; Response::build_from(self.responder.respond()?) - .header_adjoin(HyperSetCookie(cookie)) + .header_adjoin(header::SetCookie(cookie)) .ok() } } diff --git a/lib/src/rocket.rs b/lib/src/rocket.rs index a68326b7..78b3f92f 100644 --- a/lib/src/rocket.rs +++ b/lib/src/rocket.rs @@ -19,8 +19,7 @@ use outcome::Outcome; use error::Error; use http::{Method, Status}; -use http::hyper::{self, HyperRequest, FreshHyperResponse}; -use http::hyper::{HyperServer, HyperHandler, HyperSetCookie, header}; +use http::hyper::{self, header}; /// The main `Rocket` type: used to mount routes and catchers and launch the /// application. @@ -33,15 +32,15 @@ pub struct Rocket { } #[doc(hidden)] -impl HyperHandler for Rocket { +impl hyper::Handler for Rocket { // This function tries to hide all of the Hyper-ness from Rocket. It // essentially converts Hyper types into Rocket types, then calls the // `dispatch` function, which knows nothing about Hyper. Because responding // depends on the `HyperResponse` type, this function does the actual // response processing. fn handle<'h, 'k>(&self, - hyp_req: HyperRequest<'h, 'k>, - res: FreshHyperResponse<'h>) { + hyp_req: hyper::Request<'h, 'k>, + res: hyper::FreshResponse<'h>) { // Get all of the information from Hyper. let (_, h_method, h_headers, h_uri, _, h_body) = hyp_req.deconstruct(); @@ -87,7 +86,7 @@ impl HyperHandler for Rocket { // We have a response from the user. Update the cookies in the header. let cookie_delta = request.cookies().delta(); if cookie_delta.len() > 0 { - response.adjoin_header(HyperSetCookie(cookie_delta)); + response.adjoin_header(header::SetCookie(cookie_delta)); } // Actually write out the response. @@ -97,7 +96,7 @@ impl HyperHandler for Rocket { impl Rocket { #[inline] - fn issue_response(&self, mut response: Response, hyp_res: FreshHyperResponse) { + fn issue_response(&self, mut response: Response, hyp_res: hyper::FreshResponse) { // Add the 'rocket' server header, and write out the response. // TODO: If removing Hyper, write out `Data` header too. response.set_header(header::Server("rocket".to_string())); @@ -109,7 +108,7 @@ impl Rocket { } fn write_response(&self, mut response: Response, - mut hyp_res: FreshHyperResponse) -> io::Result<()> + mut hyp_res: hyper::FreshResponse) -> io::Result<()> { *hyp_res.status_mut() = hyper::StatusCode::from_u16(response.status().code); @@ -429,7 +428,7 @@ impl Rocket { } let full_addr = format!("{}:{}", self.address, self.port); - let server = match HyperServer::http(full_addr.as_str()) { + let server = match hyper::Server::http(full_addr.as_str()) { Ok(hyper_server) => hyper_server, Err(e) => { error!("failed to start server."); diff --git a/lib/src/testing.rs b/lib/src/testing.rs index 83a0567f..6f9f657d 100644 --- a/lib/src/testing.rs +++ b/lib/src/testing.rs @@ -132,7 +132,7 @@ impl MockRequest { /// ]); /// ``` pub fn headers<'h, H: AsRef<[(&'h str, &'h str)]>>(mut self, headers: H) -> Self { - let mut hyp_headers = hyper::HyperHeaders::new(); + let mut hyp_headers = hyper::header::Headers::new(); for &(name, fields) in headers.as_ref() { let mut vec_fields = vec![];