mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 05:41:50 +01:00
Add Client::request_from
This commit is contained in:
parent
b7570b2476
commit
b6b37d3ea3
@ -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>,
|
||||
|
@ -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>,
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user