From 9c80fdbb9e2ffb717e7126a453e815e8c47be459 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Fri, 29 Sep 2017 18:12:55 -0700 Subject: [PATCH] refactor(lib): rename http_types to http --- src/client/compat_impl.rs | 8 +++--- src/client/mod.rs | 4 +-- src/header/mod.rs | 28 ++++++++++---------- src/lib.rs | 2 +- src/method.rs | 54 +++++++++++++++++++-------------------- src/proto/request.rs | 14 +++++----- src/proto/response.rs | 14 +++++----- src/server/compat_impl.rs | 8 +++--- src/server/mod.rs | 6 ++--- src/status.rs | 18 ++++++------- src/uri.rs | 12 ++++----- src/version.rs | 26 +++++++++---------- 12 files changed, 97 insertions(+), 97 deletions(-) diff --git a/src/client/compat_impl.rs b/src/client/compat_impl.rs index 6887114f4a..a8a8a03863 100644 --- a/src/client/compat_impl.rs +++ b/src/client/compat_impl.rs @@ -1,5 +1,5 @@ use futures::{Future, Poll, Stream}; -use http_types; +use http; use tokio_service::Service; use client::{Connect, Client, FutureResponse}; @@ -21,8 +21,8 @@ where C: Connect, B: Stream + 'static, B::Item: AsRef<[u8]>, { - type Request = http_types::Request; - type Response = http_types::Response; + type Request = http::Request; + type Response = http::Response; type Error = Error; type Future = CompatFutureResponse; @@ -43,7 +43,7 @@ pub fn future(fut: FutureResponse) -> CompatFutureResponse { } impl Future for CompatFutureResponse { - type Item = http_types::Response; + type Item = http::Response; type Error = Error; fn poll(&mut self) -> Poll { diff --git a/src/client/mod.rs b/src/client/mod.rs index 93c0f5a02d..ba29f628f4 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -10,7 +10,7 @@ use std::time::Duration; use futures::{future, Poll, Async, Future, Stream}; use futures::unsync::oneshot; #[cfg(feature = "compat")] -use http_types; +use http; use tokio_io::{AsyncRead, AsyncWrite}; use tokio::reactor::Handle; use tokio_proto::BindClient; @@ -118,7 +118,7 @@ where C: Connect, /// Send an `http::Request` using this Client. #[inline] #[cfg(feature = "compat")] - pub fn request_compat(&self, req: http_types::Request) -> compat::CompatFutureResponse { + pub fn request_compat(&self, req: http::Request) -> compat::CompatFutureResponse { self::compat_impl::future(self.call(req.into())) } diff --git a/src/header/mod.rs b/src/header/mod.rs index 56969d7683..0dc3a30bd6 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -83,7 +83,7 @@ use std::iter::{FromIterator, IntoIterator}; use std::{mem, fmt}; #[cfg(feature = "compat")] -use http_types; +use http; use unicase::Ascii; @@ -552,8 +552,8 @@ impl fmt::Debug for Headers { } #[cfg(feature = "compat")] -impl From for Headers { - fn from(mut header_map: http_types::HeaderMap) -> Headers { +impl From for Headers { + fn from(mut header_map: http::HeaderMap) -> Headers { let mut headers = Headers::new(); for (name, mut value_drain) in header_map.drain() { if let Some(first_value) = value_drain.next() { @@ -569,23 +569,23 @@ impl From for Headers { } #[cfg(feature = "compat")] -impl From for http_types::HeaderMap { - fn from(headers: Headers) -> http_types::HeaderMap { - let mut header_map = http_types::HeaderMap::new(); +impl From for http::HeaderMap { + fn from(headers: Headers) -> http::HeaderMap { + let mut header_map = http::HeaderMap::new(); for header in headers.iter() { let entry = header_map.entry(header.name()) .expect("attempted to convert invalid header name"); let mut value_iter = header.raw().iter().map(|line| { - http_types::header::HeaderValue::from_bytes(line) + http::header::HeaderValue::from_bytes(line) .expect("attempted to convert invalid header value") }); match entry { - http_types::header::Entry::Occupied(mut occupied) => { + http::header::Entry::Occupied(mut occupied) => { for value in value_iter { occupied.append(value); } }, - http_types::header::Entry::Vacant(vacant) => { + http::header::Entry::Vacant(vacant) => { if let Some(first_value) = value_iter.next() { let mut occupied = vacant.insert_entry(first_value); for value in value_iter { @@ -996,7 +996,7 @@ mod tests { #[test] #[cfg(feature = "compat")] fn test_compat() { - use http_types; + use http; let mut orig_hyper_headers = Headers::new(); orig_hyper_headers.set(ContentLength(11)); @@ -1004,14 +1004,14 @@ mod tests { orig_hyper_headers.append_raw("x-foo", b"bar".to_vec()); orig_hyper_headers.append_raw("x-foo", b"quux".to_vec()); - let mut orig_http_headers = http_types::HeaderMap::new(); - orig_http_headers.insert(http_types::header::CONTENT_LENGTH, "11".parse().unwrap()); - orig_http_headers.insert(http_types::header::HOST, "foo.bar".parse().unwrap()); + let mut orig_http_headers = http::HeaderMap::new(); + orig_http_headers.insert(http::header::CONTENT_LENGTH, "11".parse().unwrap()); + orig_http_headers.insert(http::header::HOST, "foo.bar".parse().unwrap()); orig_http_headers.append("x-foo", "bar".parse().unwrap()); orig_http_headers.append("x-foo", "quux".parse().unwrap()); let conv_hyper_headers: Headers = orig_http_headers.clone().into(); - let conv_http_headers: http_types::HeaderMap = orig_hyper_headers.clone().into(); + let conv_http_headers: http::HeaderMap = orig_hyper_headers.clone().into(); assert_eq!(orig_hyper_headers, conv_hyper_headers); assert_eq!(orig_http_headers, conv_http_headers); } diff --git a/src/lib.rs b/src/lib.rs index 896be6402b..2dc64bfb14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ extern crate bytes; #[macro_use] extern crate futures; extern crate futures_cpupool; #[cfg(feature = "compat")] -extern crate http as http_types; +extern crate http; extern crate httparse; extern crate language_tags; #[macro_use] extern crate log; diff --git a/src/method.rs b/src/method.rs index 35d83ff5a7..c91199c0a8 100644 --- a/src/method.rs +++ b/src/method.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use std::convert::AsRef; #[cfg(feature = "compat")] -use http_types; +use http; use error::Error; use self::Method::{Options, Get, Post, Put, Delete, Head, Trace, Connect, Patch, @@ -160,26 +160,26 @@ impl Default for Method { } #[cfg(feature = "compat")] -impl From for Method { - fn from(method: http_types::Method) -> Method { +impl From for Method { + fn from(method: http::Method) -> Method { match method { - http_types::Method::GET => + http::Method::GET => Method::Get, - http_types::Method::POST => + http::Method::POST => Method::Post, - http_types::Method::PUT => + http::Method::PUT => Method::Put, - http_types::Method::DELETE => + http::Method::DELETE => Method::Delete, - http_types::Method::HEAD => + http::Method::HEAD => Method::Head, - http_types::Method::OPTIONS => + http::Method::OPTIONS => Method::Options, - http_types::Method::CONNECT => + http::Method::CONNECT => Method::Connect, - http_types::Method::PATCH => + http::Method::PATCH => Method::Patch, - http_types::Method::TRACE => + http::Method::TRACE => Method::Trace, _ => { method.as_ref().parse() @@ -190,29 +190,29 @@ impl From for Method { } #[cfg(feature = "compat")] -impl From for http_types::Method { - fn from(method: Method) -> http_types::Method { - use http_types::HttpTryFrom; +impl From for http::Method { + fn from(method: Method) -> http::Method { + use http::HttpTryFrom; match method { Method::Get => - http_types::Method::GET, + http::Method::GET, Method::Post => - http_types::Method::POST, + http::Method::POST, Method::Put => - http_types::Method::PUT, + http::Method::PUT, Method::Delete => - http_types::Method::DELETE, + http::Method::DELETE, Method::Head => - http_types::Method::HEAD, + http::Method::HEAD, Method::Options => - http_types::Method::OPTIONS, + http::Method::OPTIONS, Method::Connect => - http_types::Method::CONNECT, + http::Method::CONNECT, Method::Patch => - http_types::Method::PATCH, + http::Method::PATCH, Method::Trace => - http_types::Method::TRACE, + http::Method::TRACE, Method::Extension(s) => { HttpTryFrom::try_from(s.as_str()) .expect("attempted to convert invalid method") @@ -279,7 +279,7 @@ mod tests { #[test] #[cfg(feature = "compat")] fn test_compat() { - use http_types::{self, HttpTryFrom}; + use http::{self, HttpTryFrom}; let methods = vec![ "GET", @@ -289,9 +289,9 @@ mod tests { ]; for method in methods { let orig_hyper_method = Method::from_str(method).unwrap(); - let orig_http_method = http_types::Method::try_from(method).unwrap(); + let orig_http_method = http::Method::try_from(method).unwrap(); let conv_hyper_method: Method = orig_http_method.clone().into(); - let conv_http_method: http_types::Method = orig_hyper_method.clone().into(); + let conv_http_method: http::Method = orig_hyper_method.clone().into(); assert_eq!(orig_hyper_method, conv_hyper_method); assert_eq!(orig_http_method, conv_http_method); } diff --git a/src/proto/request.rs b/src/proto/request.rs index b9a7e5a593..8c3ef18367 100644 --- a/src/proto/request.rs +++ b/src/proto/request.rs @@ -4,7 +4,7 @@ use std::mem::replace; use std::net::SocketAddr; #[cfg(feature = "compat")] -use http_types; +use http; use header::Headers; use proto::{Body, MessageHead, RequestHead, RequestLine}; @@ -138,11 +138,11 @@ impl fmt::Debug for Request { } #[cfg(feature = "compat")] -impl From for http_types::Request { - fn from(from_req: Request) -> http_types::Request { +impl From for http::Request { + fn from(from_req: Request) -> http::Request { let (m, u, v, h, b) = from_req.deconstruct(); - let to_req = http_types::Request::new(()); + let to_req = http::Request::new(()); let (mut to_parts, _) = to_req.into_parts(); to_parts.method = m.into(); @@ -150,13 +150,13 @@ impl From for http_types::Request { to_parts.version = v.into(); to_parts.headers = h.into(); - http_types::Request::from_parts(to_parts, b) + http::Request::from_parts(to_parts, b) } } #[cfg(feature = "compat")] -impl From> for Request { - fn from(from_req: http_types::Request) -> Request { +impl From> for Request { + fn from(from_req: http::Request) -> Request { let (from_parts, body) = from_req.into_parts(); let mut to_req = Request::new(from_parts.method.into(), from_parts.uri.into()); diff --git a/src/proto/response.rs b/src/proto/response.rs index 5d59009944..950b963ee9 100644 --- a/src/proto/response.rs +++ b/src/proto/response.rs @@ -3,7 +3,7 @@ use std::fmt; use std::mem::replace; #[cfg(feature = "compat")] -use http_types; +use http; use header::{Header, Headers}; use proto::{MessageHead, ResponseHead, Body}; @@ -148,8 +148,8 @@ impl fmt::Debug for Response { } #[cfg(feature = "compat")] -impl From> for Response { - fn from(from_res: http_types::Response) -> Response { +impl From> for Response { + fn from(from_res: http::Response) -> Response { let (from_parts, body) = from_res.into_parts(); let mut to_res = Response::new(); to_res.version = from_parts.version.into(); @@ -160,14 +160,14 @@ impl From> for Response { } #[cfg(feature = "compat")] -impl From for http_types::Response { - fn from(mut from_res: Response) -> http_types::Response { - let (mut to_parts, ()) = http_types::Response::new(()).into_parts(); +impl From for http::Response { + fn from(mut from_res: Response) -> http::Response { + let (mut to_parts, ()) = http::Response::new(()).into_parts(); to_parts.version = from_res.version().into(); to_parts.status = from_res.status().into(); let from_headers = replace(from_res.headers_mut(), Headers::new()); to_parts.headers = from_headers.into(); - http_types::Response::from_parts(to_parts, from_res.body()) + http::Response::from_parts(to_parts, from_res.body()) } } diff --git a/src/server/compat_impl.rs b/src/server/compat_impl.rs index 6566042305..d8067a1a48 100644 --- a/src/server/compat_impl.rs +++ b/src/server/compat_impl.rs @@ -1,7 +1,7 @@ use std::io::{Error as IoError}; use futures::{Future, Poll}; -use http_types; +use http; use tokio_service::{NewService, Service}; use error::Error; @@ -17,7 +17,7 @@ pub struct CompatFuture { } impl Future for CompatFuture - where F: Future, Error=Error> + where F: Future, Error=Error> { type Item = Response; type Error = Error; @@ -41,7 +41,7 @@ pub fn service(service: S) -> CompatService { } impl Service for CompatService - where S: Service, Response=http_types::Response, Error=Error> + where S: Service, Response=http::Response, Error=Error> { type Request = Request; type Response = Response; @@ -68,7 +68,7 @@ pub fn new_service(new_service: S) -> NewCompatService { } impl NewService for NewCompatService - where S: NewService, Response=http_types::Response, Error=Error> + where S: NewService, Response=http::Response, Error=Error> { type Request = Request; type Response = Response; diff --git a/src/server/mod.rs b/src/server/mod.rs index c36b37226d..5da465126f 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -22,7 +22,7 @@ use futures::{Future, Stream, Poll, Async, Sink, StartSend, AsyncSink}; use futures::future::Map; #[cfg(feature = "compat")] -use http_types; +use http; use tokio_io::{AsyncRead, AsyncWrite}; use tokio::reactor::{Core, Handle, Timeout}; @@ -129,7 +129,7 @@ impl + 'static> Http { /// See `Http::bind`. #[cfg(feature = "compat")] pub fn bind_compat(&self, addr: &SocketAddr, new_service: S) -> ::Result, Bd>> - where S: NewService, Response = http_types::Response, Error = ::Error> + + where S: NewService, Response = http::Response, Error = ::Error> + Send + Sync + 'static, Bd: Stream, { @@ -174,7 +174,7 @@ impl + 'static> Http { io: I, remote_addr: SocketAddr, service: S) - where S: Service, Response = http_types::Response, Error = ::Error> + 'static, + where S: Service, Response = http::Response, Error = ::Error> + 'static, Bd: Stream + 'static, I: AsyncRead + AsyncWrite + 'static, { diff --git a/src/status.rs b/src/status.rs index 4884613532..bc09328363 100644 --- a/src/status.rs +++ b/src/status.rs @@ -3,7 +3,7 @@ use std::fmt; use std::cmp::Ordering; #[cfg(feature = "compat")] -use http_types; +use http; /// An HTTP status code (`status-code` in RFC 7230 et al.). /// @@ -600,17 +600,17 @@ impl From for u16 { } #[cfg(feature = "compat")] -impl From for StatusCode { - fn from(status: http_types::StatusCode) -> StatusCode { +impl From for StatusCode { + fn from(status: http::StatusCode) -> StatusCode { StatusCode::try_from(status.as_u16()) .expect("attempted to convert invalid status code") } } #[cfg(feature = "compat")] -impl From for http_types::StatusCode { - fn from(status: StatusCode) -> http_types::StatusCode { - http_types::StatusCode::from_u16(status.as_u16()) +impl From for http::StatusCode { + fn from(status: StatusCode) -> http::StatusCode { + http::StatusCode::from_u16(status.as_u16()) .expect("attempted to convert invalid status code") } } @@ -769,12 +769,12 @@ mod tests { #[test] #[cfg(feature = "compat")] fn test_compat() { - use http_types::{self, HttpTryFrom}; + use http::{self, HttpTryFrom}; for i in 100..600 { let orig_hyper_status = StatusCode::try_from(i).unwrap(); - let orig_http_status = http_types::StatusCode::try_from(i).unwrap(); + let orig_http_status = http::StatusCode::try_from(i).unwrap(); let conv_hyper_status: StatusCode = orig_http_status.into(); - let conv_http_status: http_types::StatusCode = orig_hyper_status.into(); + let conv_http_status: http::StatusCode = orig_hyper_status.into(); assert_eq!(orig_hyper_status, conv_hyper_status); assert_eq!(orig_http_status, conv_http_status); } diff --git a/src/uri.rs b/src/uri.rs index 4e710ec4c3..bfab852be2 100644 --- a/src/uri.rs +++ b/src/uri.rs @@ -3,7 +3,7 @@ use std::fmt::{Display, self}; use std::str::{self, FromStr}; #[cfg(feature = "compat")] -use http_types; +use http; use ::common::ByteStr; use bytes::{BufMut, Bytes, BytesMut}; @@ -319,18 +319,18 @@ impl Display for Uri { } #[cfg(feature = "compat")] -impl From for Uri { - fn from(uri: http_types::Uri) -> Uri { +impl From for Uri { + fn from(uri: http::Uri) -> Uri { uri.to_string().parse() .expect("attempted to convert invalid uri") } } #[cfg(feature = "compat")] -impl From for http_types::Uri { - fn from(uri: Uri) -> http_types::Uri { +impl From for http::Uri { + fn from(uri: Uri) -> http::Uri { let bytes = uri.source.into_bytes(); - http_types::Uri::from_shared(bytes) + http::Uri::from_shared(bytes) .expect("attempted to convert invalid uri") } } diff --git a/src/version.rs b/src/version.rs index 4d303ad34f..ddb7d1a020 100644 --- a/src/version.rs +++ b/src/version.rs @@ -6,7 +6,7 @@ use std::fmt; use std::str::FromStr; #[cfg(feature = "compat")] -use http_types; +use http; use error::Error; use self::HttpVersion::{Http09, Http10, Http11, H2, H2c}; @@ -62,33 +62,33 @@ impl Default for HttpVersion { } #[cfg(feature = "compat")] -impl From for HttpVersion { - fn from(v: http_types::Version) -> HttpVersion { +impl From for HttpVersion { + fn from(v: http::Version) -> HttpVersion { match v { - http_types::Version::HTTP_09 => + http::Version::HTTP_09 => HttpVersion::Http09, - http_types::Version::HTTP_10 => + http::Version::HTTP_10 => HttpVersion::Http10, - http_types::Version::HTTP_11 => + http::Version::HTTP_11 => HttpVersion::Http11, - http_types::Version::HTTP_2 => + http::Version::HTTP_2 => HttpVersion::H2 } } } #[cfg(feature = "compat")] -impl From for http_types::Version { - fn from(v: HttpVersion) -> http_types::Version { +impl From for http::Version { + fn from(v: HttpVersion) -> http::Version { match v { HttpVersion::Http09 => - http_types::Version::HTTP_09, + http::Version::HTTP_09, HttpVersion::Http10 => - http_types::Version::HTTP_10, + http::Version::HTTP_10, HttpVersion::Http11 => - http_types::Version::HTTP_11, + http::Version::HTTP_11, HttpVersion::H2 => - http_types::Version::HTTP_2, + http::Version::HTTP_2, _ => panic!("attempted to convert unexpected http version") } }