chore(client): place the use of new rust features behind cfg
This commit is contained in:
committed by
Sean McArthur
parent
97f4243a59
commit
9f8add6056
@@ -1,5 +1,4 @@
|
||||
[package]
|
||||
|
||||
name = "hyper"
|
||||
version = "0.12.7" # don't forget to update html_root_url
|
||||
description = "A fast and correct HTTP library."
|
||||
@@ -50,6 +49,9 @@ serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
|
||||
[build-dependencies]
|
||||
rustc_version = "0.2.3"
|
||||
|
||||
[features]
|
||||
default = [
|
||||
"__internal_flaky_tests",
|
||||
|
||||
14
build.rs
Normal file
14
build.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
extern crate rustc_version;
|
||||
use rustc_version::{version, Version};
|
||||
|
||||
fn main() {
|
||||
|
||||
// Check for a minimum version to see if new rust features can be used
|
||||
let version = version().unwrap();
|
||||
if version >= Version::parse("1.26.0").unwrap() {
|
||||
println!("cargo:rustc-cfg=impl_trait_available");
|
||||
}
|
||||
if version >= Version::parse("1.23.0").unwrap() {
|
||||
println!("cargo:rustc-cfg=inherent_ascii");
|
||||
}
|
||||
}
|
||||
@@ -238,6 +238,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(impl_trait_available)]
|
||||
pub(crate) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item = Response<Body>, Error = (::Error, Option<Request<B>>)> + Send
|
||||
where
|
||||
B: Send,
|
||||
@@ -260,6 +261,31 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(impl_trait_available))]
|
||||
pub(super) fn send_request_retryable(&mut self, req: Request<B>) -> Box<Future<Item=Response<Body>, Error=(::Error, Option<Request<B>>)> + Send>
|
||||
where
|
||||
B: Send,
|
||||
{
|
||||
let inner = match self.dispatch.try_send(req) {
|
||||
Ok(rx) => {
|
||||
Either::A(rx.then(move |res| {
|
||||
match res {
|
||||
Ok(Ok(res)) => Ok(res),
|
||||
Ok(Err(err)) => Err(err),
|
||||
// this is definite bug if it happens, but it shouldn't happen!
|
||||
Err(_) => panic!("dispatch dropped without returning error"),
|
||||
}
|
||||
}))
|
||||
},
|
||||
Err(req) => {
|
||||
debug!("connection was not ready");
|
||||
let err = ::Error::new_canceled(Some("connection was not ready"));
|
||||
Either::B(future::err((err, Some(req))))
|
||||
}
|
||||
};
|
||||
Box::new(inner)
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO(0.12.0): when we change from tokio-service to tower.
|
||||
@@ -298,6 +324,7 @@ impl<B> Http2SendRequest<B>
|
||||
where
|
||||
B: Payload + 'static,
|
||||
{
|
||||
#[cfg(impl_trait_available)]
|
||||
pub(super) fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item=Response<Body>, Error=(::Error, Option<Request<B>>)> + Send
|
||||
where
|
||||
B: Send,
|
||||
@@ -320,6 +347,31 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(impl_trait_available))]
|
||||
pub(crate) fn send_request_retryable(&mut self, req: Request<B>) -> Box<Future<Item=Response<Body>, Error=(::Error, Option<Request<B>>)> + Send>
|
||||
where
|
||||
B: Send,
|
||||
{
|
||||
let inner = match self.dispatch.try_send(req) {
|
||||
Ok(rx) => {
|
||||
Either::A(rx.then(move |res| {
|
||||
match res {
|
||||
Ok(Ok(res)) => Ok(res),
|
||||
Ok(Err(err)) => Err(err),
|
||||
// this is definite bug if it happens, but it shouldn't happen!
|
||||
Err(_) => panic!("dispatch dropped without returning error"),
|
||||
}
|
||||
}))
|
||||
},
|
||||
Err(req) => {
|
||||
debug!("connection was not ready");
|
||||
let err = ::Error::new_canceled(Some("connection was not ready"));
|
||||
Either::B(future::err((err, Some(req))))
|
||||
}
|
||||
};
|
||||
Box::new(inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> fmt::Debug for Http2SendRequest<B> {
|
||||
|
||||
@@ -623,6 +623,7 @@ impl<B> PoolClient<B> {
|
||||
}
|
||||
|
||||
impl<B: Payload + 'static> PoolClient<B> {
|
||||
#[cfg(impl_trait_available)]
|
||||
fn send_request_retryable(&mut self, req: Request<B>) -> impl Future<Item = Response<Body>, Error = (::Error, Option<Request<B>>)> + Send
|
||||
where
|
||||
B: Send,
|
||||
@@ -632,6 +633,17 @@ impl<B: Payload + 'static> PoolClient<B> {
|
||||
PoolTx::Http2(ref mut tx) => Either::B(tx.send_request_retryable(req)),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(impl_trait_available))]
|
||||
fn send_request_retryable(&mut self, req: Request<B>) -> Box<Future<Item=Response<Body>, Error=(::Error, Option<Request<B>>)> + Send>
|
||||
where
|
||||
B: Send,
|
||||
{
|
||||
match self.tx {
|
||||
PoolTx::Http1(ref mut tx) => tx.send_request_retryable(req),
|
||||
PoolTx::Http2(ref mut tx) => tx.send_request_retryable(req),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> Poolable for PoolClient<B>
|
||||
|
||||
@@ -2,6 +2,8 @@ use bytes::BytesMut;
|
||||
use http::HeaderMap;
|
||||
use http::header::{CONTENT_LENGTH, TRANSFER_ENCODING};
|
||||
use http::header::{HeaderValue, OccupiedEntry, ValueIter};
|
||||
#[cfg(not(inherent_ascii))]
|
||||
use std::ascii::AsciiExt;
|
||||
|
||||
pub fn connection_keep_alive(value: &HeaderValue) -> bool {
|
||||
connection_has(value, "keep-alive")
|
||||
|
||||
Reference in New Issue
Block a user