1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-10-02 16:22:03 +00:00

Add Client::request_from

This commit is contained in:
Nikolay Kim 2019-03-26 23:25:24 -07:00
parent b7570b2476
commit b6b37d3ea3
3 changed files with 21 additions and 3 deletions

View file

@ -3,7 +3,7 @@ use std::rc::Rc;
pub use actix_http::client::{ConnectError, InvalidUrl, SendRequestError};
pub use actix_http::error::PayloadError;
pub use actix_http::http;
pub use actix_http::{http, RequestHead};
use actix_http::client::Connector;
use actix_http::http::{HttpTryFrom, Method, Uri};
@ -76,6 +76,24 @@ impl Client {
ClientRequest::new(method, url, self.connector.clone())
}
/// Create `ClientRequest` from `RequestHead`
///
/// It is useful for proxy requests. This implementation
/// copies all headers and the method.
pub fn request_from<U>(&self, url: U, head: &RequestHead) -> ClientRequest
where
Uri: HttpTryFrom<U>,
{
let mut req =
ClientRequest::new(head.method.clone(), url, self.connector.clone());
for (key, value) in &head.headers {
req.head.headers.insert(key.clone(), value.clone());
}
req
}
pub fn get<U>(&self, url: U) -> ClientRequest
where
Uri: HttpTryFrom<U>,

View file

@ -56,7 +56,7 @@ const HTTPS_ENCODING: &str = "gzip, deflate";
/// }
/// ```
pub struct ClientRequest {
head: RequestHead,
pub(crate) head: RequestHead,
err: Option<HttpError>,
#[cfg(feature = "cookies")]
cookies: Option<CookieJar>,

View file

@ -7,7 +7,7 @@ use futures::{Future, Poll, Stream};
use actix_http::error::PayloadError;
use actix_http::http::header::{CONTENT_LENGTH, SET_COOKIE};
use actix_http::http::{HeaderMap, StatusCode, Version};
use actix_http::{Extensions, Head, HttpMessage, Payload, PayloadStream, ResponseHead};
use actix_http::{Extensions, HttpMessage, Payload, PayloadStream, ResponseHead};
#[cfg(feature = "cookies")]
use actix_http::error::CookieParseError;