pub async fn proxy_to_and_forward_response(
proxy_address: String,
base_path: String,
uri: FullPath,
params: QueryParameters,
method: Method,
headers: HeaderMap,
body: Bytes,
) -> Result<Response, Rejection>Expand description
Build a request and send to the requested address.
Wraps the response into a warp::reply compatible type (http::Response)
§Arguments
-
proxy_address- A string containing the base proxy address where the request will be forwarded to. -
base_path- A string with the prepended sub-path to be stripped from the request uri path. -
uri-> The uri of the extracted request. -
params-> The URL query parameters -
method-> The request method. -
headers-> The request headers. -
body-> The request body.
§Examples
Notice that this method usually need to be used in aggregation with
the extract_request_data_filter filter which already
provides the (Uri, QueryParameters, Method, Headers, Body) needed for calling this method. But the proxy_address
and the base_path arguments need to be provided too.
use warp::{Filter, Reply, Rejection, reply::Response};
use warp_reverse_proxy::{extract_request_data_filter, proxy_to_and_forward_response};
async fn log_response(response: Response) -> Result<impl Reply, Rejection> {
println!("{:?}", response);
Ok(response)
}
let request_filter = extract_request_data_filter();
let app = warp::path!("hello" / String)
.map(|port| (format!("http://127.0.0.1:{}/", port), "".to_string()))
.untuple_one()
.and(request_filter)
.and_then(proxy_to_and_forward_response)
.and_then(log_response);