From 6101dd6cb264333c05cac8c2fb111493b38467c2 Mon Sep 17 00:00:00 2001 From: Kiron Date: Wed, 22 Nov 2023 16:03:57 +0800 Subject: [PATCH 1/2] fix(examples): send only path of URI in request --- examples/client.rs | 3 ++- examples/client_json.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/client.rs b/examples/client.rs index 046f59de02..4bf7b69a1a 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -54,9 +54,10 @@ async fn fetch_url(url: hyper::Uri) -> Result<()> { }); let authority = url.authority().unwrap().clone(); + let uri = url.path_and_query().map(|p| p.as_str()).unwrap_or("/"); let req = Request::builder() - .uri(url) + .uri(uri) .header(hyper::header::HOST, authority.as_str()) .body(Empty::::new())?; diff --git a/examples/client_json.rs b/examples/client_json.rs index 6a6753528c..8618aca120 100644 --- a/examples/client_json.rs +++ b/examples/client_json.rs @@ -43,10 +43,11 @@ async fn fetch_json(url: hyper::Uri) -> Result> { }); let authority = url.authority().unwrap().clone(); + let uri = url.path_and_query().map(|p| p.as_str()).unwrap_or("/"); // Fetch the url... let req = Request::builder() - .uri(url) + .uri(uri) .header(hyper::header::HOST, authority.as_str()) .body(Empty::::new())?; From a66e1067a39fe5174cb1fe8c20a091135c9bb622 Mon Sep 17 00:00:00 2001 From: Kiron Date: Wed, 22 Nov 2023 17:35:15 +0800 Subject: [PATCH 2/2] fix(examples): send path of URI in proxied request --- examples/http_proxy.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/http_proxy.rs b/examples/http_proxy.rs index 2dbc5c9ac7..7f981fc2a1 100644 --- a/examples/http_proxy.rs +++ b/examples/http_proxy.rs @@ -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; @@ -49,7 +50,7 @@ async fn main() -> Result<(), Box> { } async fn proxy( - req: Request, + mut req: Request, ) -> Result>, hyper::Error> { println!("req: {:?}", req); @@ -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())) }