diff --git a/.travis.yml b/.travis.yml index 8de1691..c29af10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,13 @@ matrix: - rust: nightly env: FEATURES="" + - rust: stable + env: FEATURES="--features hyper-011" + - rust: beta + env: FEATURES="--features hyper-011" + - rust: nightly + env: FEATURES="--features hyper-011" + # minimum version - rust: 1.21.0 script: cargo build diff --git a/Cargo.toml b/Cargo.toml index c1ec7b1..ff76ea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ encoding_rs = "0.7" futures = "0.1.21" http = "0.1.5" hyper = "0.12.2" +hyper-old-types = { version = "0.11", optional = true, features = ["compat"] } hyper-tls = "0.3" libflate = "0.1.11" log = "0.4" @@ -38,4 +39,5 @@ error-chain = "0.10" serde_derive = "1.0" [features] - +default = [] +hyper-011 = ["hyper-old-types"] diff --git a/src/async_impl/request.rs b/src/async_impl/request.rs index ef4d6b7..96953e8 100644 --- a/src/async_impl/request.rs +++ b/src/async_impl/request.rs @@ -122,6 +122,31 @@ impl RequestBuilder { self } + /// Set a header with a type implementing hyper v0.11's `Header` trait. + /// + /// This method is provided to ease migration, and requires the `hyper-011` + /// Cargo feature enabled on `reqwest`. + #[cfg(feature = "hyper-011")] + pub fn header_011(self, header: H) -> RequestBuilder + where + H: ::hyper_011::header::Header, + { + let mut headers = ::hyper_011::Headers::new(); + headers.set(header); + let map = ::header::HeaderMap::from(headers); + self.headers(map) + } + + /// Set multiple headers using hyper v0.11's `Headers` map. + /// + /// This method is provided to ease migration, and requires the `hyper-011` + /// Cargo feature enabled on `reqwest`. + #[cfg(feature = "hyper-011")] + pub fn headers_011(self, headers: ::hyper_011::Headers) -> RequestBuilder { + let map = ::header::HeaderMap::from(headers); + self.headers(map) + } + /// Enable HTTP basic authentication. pub fn basic_auth(self, username: U, password: Option

) -> RequestBuilder where diff --git a/src/lib.rs b/src/lib.rs index aed7345..7431d64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -131,6 +131,8 @@ extern crate encoding_rs; extern crate futures; extern crate http; extern crate hyper; +#[cfg(feature = "hyper-011")] +pub extern crate hyper_old_types as hyper_011; extern crate hyper_tls; #[macro_use] extern crate log; diff --git a/src/request.rs b/src/request.rs index d034a03..e30cb14 100644 --- a/src/request.rs +++ b/src/request.rs @@ -175,6 +175,31 @@ impl RequestBuilder { self } + /// Set a header with a type implementing hyper v0.11's `Header` trait. + /// + /// This method is provided to ease migration, and requires the `hyper-011` + /// Cargo feature enabled on `reqwest`. + #[cfg(feature = "hyper-011")] + pub fn header_011(self, header: H) -> RequestBuilder + where + H: ::hyper_011::header::Header, + { + let mut headers = ::hyper_011::Headers::new(); + headers.set(header); + let map = ::header::HeaderMap::from(headers); + self.headers(map) + } + + /// Set multiple headers using hyper v0.11's `Headers` map. + /// + /// This method is provided to ease migration, and requires the `hyper-011` + /// Cargo feature enabled on `reqwest`. + #[cfg(feature = "hyper-011")] + pub fn headers_011(self, headers: ::hyper_011::Headers) -> RequestBuilder { + let map = ::header::HeaderMap::from(headers); + self.headers(map) + } + /// Enable HTTP basic authentication. /// /// ```rust