Skip to content

Commit 952756b

Browse files
authored
docs(examples): include Host header in client examples (#2956)
1 parent 84f6ae7 commit 952756b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

examples/client.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ async fn fetch_url(url: hyper::Uri) -> Result<()> {
4646
}
4747
});
4848

49-
let req = Request::builder().uri(url).body(Body::empty()).unwrap();
49+
let authority = url.authority().unwrap().clone();
50+
51+
let req = Request::builder()
52+
.uri(url)
53+
.header(hyper::header::HOST, authority.as_str())
54+
.body(Body::empty())?;
55+
5056
let mut res = sender.send_request(req).await?;
5157

5258
println!("Response: {}", res.status());

examples/client_json.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ async fn fetch_json(url: hyper::Uri) -> Result<Vec<User>> {
3636
}
3737
});
3838

39+
let authority = url.authority().unwrap().clone();
40+
3941
// Fetch the url...
40-
let req = Request::builder().uri(url).body(Body::empty()).unwrap();
42+
let req = Request::builder()
43+
.uri(url)
44+
.header(hyper::header::HOST, authority.as_str())
45+
.body(Body::empty())?;
46+
4147
let res = sender.send_request(req).await?;
4248

4349
// asynchronously aggregate the chunks of the body

0 commit comments

Comments
 (0)