Skip to content

Commit

Permalink
fix(examples): send path of URI in proxied request
Browse files Browse the repository at this point in the history
  • Loading branch information
kiron1 committed Nov 25, 2023
1 parent 6d8bc68 commit 1fff964
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/http_proxy.rs
Expand Up @@ -3,6 +3,7 @@
use std::net::SocketAddr;

use bytes::Bytes;
use http::{uri, Uri};
use http_body_util::{combinators::BoxBody, BodyExt, Empty, Full};
use hyper::client::conn::http1::Builder;
use hyper::server::conn::http1;
Expand Down Expand Up @@ -49,7 +50,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}

async fn proxy(
req: Request<hyper::body::Incoming>,
mut req: Request<hyper::body::Incoming>,
) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
println!("req: {:?}", req);

Expand Down Expand Up @@ -105,6 +106,10 @@ async fn proxy(
}
});

let mut uri_parts = uri::Parts::default();
uri_parts.path_and_query = req.uri().path_and_query().cloned();
*req.uri_mut() = Uri::from_parts(uri_parts).unwrap();

let resp = sender.send_request(req).await?;
Ok(resp.map(|b| b.boxed()))
}
Expand Down

0 comments on commit 1fff964

Please sign in to comment.