diff --git a/CHANGES.md b/CHANGES.md index c5c0499dd..8ba3ef566 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,10 @@ * Support HTTP/2 with rustls #36 +### Fixed + +* Do not override HOST header for client request #428 + ## [0.7.2] - 2018-07-26 diff --git a/src/client/request.rs b/src/client/request.rs index 72aab259d..4d506c3fa 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -291,10 +291,6 @@ impl ClientRequestBuilder { fn _uri(&mut self, url: &str) -> &mut Self { match Uri::try_from(url) { Ok(uri) => { - // set request host header - if let Some(host) = uri.host() { - self.set_header(header::HOST, host); - } if let Some(parts) = parts(&mut self.request, &self.err) { parts.uri = uri; } @@ -629,9 +625,24 @@ impl ClientRequestBuilder { self.set_header_if_none(header::ACCEPT_ENCODING, "gzip, deflate"); } + // set request host header + if let Some(parts) = parts(&mut self.request, &self.err) { + if let Some(host) = parts.uri.host() { + if !parts.headers.contains_key(header::HOST) { + match host.try_into() { + Ok(value) => { + parts.headers.insert(header::HOST, value); + } + Err(e) => self.err = Some(e.into()), + } + } + } + } + + // user agent self.set_header_if_none( header::USER_AGENT, - concat!("Actix-web/", env!("CARGO_PKG_VERSION")), + concat!("actix-web/", env!("CARGO_PKG_VERSION")), ); }