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 30, 2023
1 parent 6101dd6 commit a66e106
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/http_proxy.rs
Original file line number Diff line number Diff line change
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 a66e106

Please sign in to comment.