diff --git a/awc/src/lib.rs b/awc/src/lib.rs index 8ce5b35f7..ac7dcf2f1 100644 --- a/awc/src/lib.rs +++ b/awc/src/lib.rs @@ -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(&self, url: U, head: &RequestHead) -> ClientRequest + where + Uri: HttpTryFrom, + { + 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(&self, url: U) -> ClientRequest where Uri: HttpTryFrom, diff --git a/awc/src/request.rs b/awc/src/request.rs index c944c6ca3..d25ecc421 100644 --- a/awc/src/request.rs +++ b/awc/src/request.rs @@ -56,7 +56,7 @@ const HTTPS_ENCODING: &str = "gzip, deflate"; /// } /// ``` pub struct ClientRequest { - head: RequestHead, + pub(crate) head: RequestHead, err: Option, #[cfg(feature = "cookies")] cookies: Option, diff --git a/awc/src/response.rs b/awc/src/response.rs index 03606a768..3b77eaa60 100644 --- a/awc/src/response.rs +++ b/awc/src/response.rs @@ -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;