diff --git a/examples/client.rs b/examples/client.rs index a64c35273b..02805d828d 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -53,12 +53,15 @@ async fn fetch_url(url: hyper::Uri) -> Result<()> { } }); - let authority = url.authority().unwrap().clone(); + let host_header = match (url.host(), url.port_u16()) { + (Some(host), Some(port)) => format!("{}:{}", host, port), + _ => url.host().unwrap().to_string(), + }; let path = url.path(); let req = Request::builder() .uri(path) - .header(hyper::header::HOST, authority.as_str()) + .header(hyper::header::HOST, host_header) .body(Empty::::new())?; let mut res = sender.send_request(req).await?; diff --git a/examples/client_json.rs b/examples/client_json.rs index 6a6753528c..0f74f2ecab 100644 --- a/examples/client_json.rs +++ b/examples/client_json.rs @@ -42,12 +42,15 @@ async fn fetch_json(url: hyper::Uri) -> Result> { } }); - let authority = url.authority().unwrap().clone(); + let host_header = match (url.host(), url.port_u16()) { + (Some(host), Some(port)) => format!("{}:{}", host, port), + _ => url.host().unwrap().to_string(), + }; // Fetch the url... let req = Request::builder() .uri(url) - .header(hyper::header::HOST, authority.as_str()) + .header(hyper::header::HOST, host_header) .body(Empty::::new())?; let res = sender.send_request(req).await?; diff --git a/examples/single_threaded.rs b/examples/single_threaded.rs index f297814c92..38989a0a96 100644 --- a/examples/single_threaded.rs +++ b/examples/single_threaded.rs @@ -181,13 +181,16 @@ async fn http1_client(url: hyper::Uri) -> Result<(), Box> } }); - let authority = url.authority().unwrap().clone(); + let host_header = match (url.host(), url.port_u16()) { + (Some(host), Some(port)) => format!("{}:{}", host, port), + _ => url.host().unwrap().to_string(), + }; // Make 4 requests for _ in 0..4 { let req = Request::builder() .uri(url.clone()) - .header(hyper::header::HOST, authority.as_str()) + .header(hyper::header::HOST, &host_header) .body(Body::from("test".to_string()))?; let mut res = sender.send_request(req).await?; @@ -282,13 +285,16 @@ async fn http2_client(url: hyper::Uri) -> Result<(), Box> } }); - let authority = url.authority().unwrap().clone(); + let host_header = match (url.host(), url.port_u16()) { + (Some(host), Some(port)) => format!("{}:{}", host, port), + _ => url.host().unwrap().to_string(), + }; // Make 4 requests for _ in 0..4 { let req = Request::builder() .uri(url.clone()) - .header(hyper::header::HOST, authority.as_str()) + .header(hyper::header::HOST, &host_header) .body(Body::from("test".to_string()))?; let mut res = sender.send_request(req).await?;