pub(crate)ify async::response module
This commit is contained in:
@@ -13,7 +13,7 @@ use native_tls::{TlsConnector, TlsConnectorBuilder};
|
|||||||
|
|
||||||
use super::body;
|
use super::body;
|
||||||
use super::request::{self, Request, RequestBuilder};
|
use super::request::{self, Request, RequestBuilder};
|
||||||
use super::response::{self, Response};
|
use super::response::Response;
|
||||||
use connect::Connector;
|
use connect::Connector;
|
||||||
use into_url::to_uri;
|
use into_url::to_uri;
|
||||||
use redirect::{self, RedirectPolicy, remove_sensitive_headers};
|
use redirect::{self, RedirectPolicy, remove_sensitive_headers};
|
||||||
@@ -29,7 +29,6 @@ static DEFAULT_USER_AGENT: &'static str =
|
|||||||
///
|
///
|
||||||
/// The `Client` holds a connection pool internally, so it is advised that
|
/// The `Client` holds a connection pool internally, so it is advised that
|
||||||
/// you create one and **reuse** it.
|
/// you create one and **reuse** it.
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
inner: Arc<ClientRef>,
|
inner: Arc<ClientRef>,
|
||||||
@@ -516,7 +515,7 @@ impl Future for PendingRequest {
|
|||||||
debug!("Location header had invalid URI: {:?}", e);
|
debug!("Location header had invalid URI: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let res = response::new(res, self.url.clone(), self.client.gzip);
|
let res = Response::new(res, self.url.clone(), self.client.gzip);
|
||||||
return Ok(Async::Ready(res));
|
return Ok(Async::Ready(res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,21 @@ pub struct Response {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
|
pub(super) fn new(mut res: ::hyper::Response<::hyper::Body>, url: Url, gzip: bool) -> Response {
|
||||||
|
let status = res.status();
|
||||||
|
let version = res.version();
|
||||||
|
let mut headers = mem::replace(res.headers_mut(), HeaderMap::new());
|
||||||
|
let decoder = decoder::detect(&mut headers, body::wrap(res.into_body()), gzip);
|
||||||
|
debug!("Response: '{}' for {}", status, url);
|
||||||
|
Response {
|
||||||
|
status: status,
|
||||||
|
headers: headers,
|
||||||
|
url: url,
|
||||||
|
body: decoder,
|
||||||
|
version: version,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the final `Url` of this `Response`.
|
/// Get the final `Url` of this `Response`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn url(&self) -> &Url {
|
pub fn url(&self) -> &Url {
|
||||||
@@ -148,20 +163,3 @@ impl<T> fmt::Debug for Json<T> {
|
|||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub(crate)
|
|
||||||
|
|
||||||
pub fn new(mut res: ::hyper::Response<::hyper::Body>, url: Url, gzip: bool) -> Response {
|
|
||||||
let status = res.status();
|
|
||||||
let version = res.version();
|
|
||||||
let mut headers = mem::replace(res.headers_mut(), HeaderMap::new());
|
|
||||||
let decoder = decoder::detect(&mut headers, body::wrap(res.into_body()), gzip);
|
|
||||||
debug!("Response: '{}' for {}", status, url);
|
|
||||||
Response {
|
|
||||||
status: status,
|
|
||||||
headers: headers,
|
|
||||||
url: url,
|
|
||||||
body: decoder,
|
|
||||||
version: version,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user