Skip to content

Commit a66e106

Browse files
committed
fix(examples): send path of URI in proxied request
1 parent 6101dd6 commit a66e106

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: examples/http_proxy.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::net::SocketAddr;
44

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

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

@@ -105,6 +106,10 @@ async fn proxy(
105106
}
106107
});
107108

109+
let mut uri_parts = uri::Parts::default();
110+
uri_parts.path_and_query = req.uri().path_and_query().cloned();
111+
*req.uri_mut() = Uri::from_parts(uri_parts).unwrap();
112+
108113
let resp = sender.send_request(req).await?;
109114
Ok(resp.map(|b| b.boxed()))
110115
}

0 commit comments

Comments
 (0)