mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
add convinience ClientRequest::build_from() from HttpRequest
This commit is contained in:
parent
4866a26578
commit
afb81b6b8f
@ -16,6 +16,8 @@ use percent_encoding::{USERINFO_ENCODE_SET, percent_encode};
|
||||
use body::Body;
|
||||
use error::Error;
|
||||
use header::{ContentEncoding, Header, IntoHeaderValue};
|
||||
use httpmessage::HttpMessage;
|
||||
use httprequest::HttpRequest;
|
||||
use super::pipeline::SendRequest;
|
||||
use super::connector::{Connection, ClientConnector};
|
||||
|
||||
@ -111,6 +113,11 @@ impl ClientRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create client request builder
|
||||
pub fn build_from<T: Into<ClientRequestBuilder>>(source: T) -> ClientRequestBuilder {
|
||||
source.into()
|
||||
}
|
||||
|
||||
/// Get the request uri
|
||||
#[inline]
|
||||
pub fn uri(&self) -> &Uri {
|
||||
@ -645,3 +652,18 @@ impl fmt::Debug for ClientRequestBuilder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Create `ClientRequestBuilder` from `HttpRequest`
|
||||
///
|
||||
/// It is useful for proxy requests. This implementation
|
||||
/// copies all request's headers and method.
|
||||
impl<'a, S: 'static> From<&'a HttpRequest<S>> for ClientRequestBuilder {
|
||||
fn from(req: &'a HttpRequest<S>) -> ClientRequestBuilder {
|
||||
let mut builder = ClientRequest::build();
|
||||
for (key, value) in req.headers() {
|
||||
builder.header(key.clone(), value.clone());
|
||||
}
|
||||
builder.method(req.method().clone());
|
||||
builder
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,12 @@ impl HttpResponse {
|
||||
}
|
||||
}
|
||||
|
||||
/// Create http response builder
|
||||
#[inline]
|
||||
pub fn build_from<T: Into<HttpResponseBuilder>>(source: T) -> HttpResponseBuilder {
|
||||
source.into()
|
||||
}
|
||||
|
||||
/// Constructs a response
|
||||
#[inline]
|
||||
pub fn new(status: StatusCode, body: Body) -> HttpResponse {
|
||||
|
Loading…
Reference in New Issue
Block a user