Skip to content

fix: Do not include user information in Host header #3621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ async fn fetch_url(url: hyper::Uri) -> Result<()> {
}
});

let authority = url.authority().unwrap().clone();

let path = url.path();
let req = Request::builder()
.uri(path)
.header(hyper::header::HOST, authority.as_str())
.header(hyper::header::HOST, format!("{}:{}", host, port))
.body(Empty::<Bytes>::new())?;

let mut res = sender.send_request(req).await?;
Expand Down
6 changes: 2 additions & 4 deletions examples/client_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ async fn fetch_json(url: hyper::Uri) -> Result<Vec<User>> {
}
});

let authority = url.authority().unwrap().clone();

// Fetch the url...
// Fetch the URL...
let req = Request::builder()
.uri(url)
.header(hyper::header::HOST, authority.as_str())
.header(hyper::header::HOST, format!("{}:{}", host, port))
.body(Empty::<Bytes>::new())?;

let res = sender.send_request(req).await?;
Expand Down
8 changes: 2 additions & 6 deletions examples/single_threaded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,11 @@ async fn http1_client(url: hyper::Uri) -> Result<(), Box<dyn std::error::Error>>
}
});

let authority = url.authority().unwrap().clone();

// 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, format!("{}:{}", host, port))
.body(Body::from("test".to_string()))?;

let mut res = sender.send_request(req).await?;
Expand Down Expand Up @@ -282,13 +280,11 @@ async fn http2_client(url: hyper::Uri) -> Result<(), Box<dyn std::error::Error>>
}
});

let authority = url.authority().unwrap().clone();

// 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, format!("{}:{}", host, port))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clients shouldn't be sending a host header with http/2.

https://tools.ietf.org/html/rfc7540#page-55

Clients that generate HTTP/2 requests directly SHOULD use the ":authority" pseudo-header field instead of the Host header field.

Hyper automatically adds the :authority from the URI. Some servers (Google) reset the connection if the host header is sent with http2.

.body(Body::from("test".to_string()))?;

let mut res = sender.send_request(req).await?;
Expand Down
Loading