1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

do not override HOST header for client request #428

This commit is contained in:
Nikolay Kim 2018-07-31 08:51:24 -07:00
parent 2072c933ba
commit 4dba531bf9
2 changed files with 20 additions and 5 deletions

View File

@ -6,6 +6,10 @@
* Support HTTP/2 with rustls #36 * Support HTTP/2 with rustls #36
### Fixed
* Do not override HOST header for client request #428
## [0.7.2] - 2018-07-26 ## [0.7.2] - 2018-07-26

View File

@ -291,10 +291,6 @@ impl ClientRequestBuilder {
fn _uri(&mut self, url: &str) -> &mut Self { fn _uri(&mut self, url: &str) -> &mut Self {
match Uri::try_from(url) { match Uri::try_from(url) {
Ok(uri) => { 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) { if let Some(parts) = parts(&mut self.request, &self.err) {
parts.uri = uri; parts.uri = uri;
} }
@ -629,9 +625,24 @@ impl ClientRequestBuilder {
self.set_header_if_none(header::ACCEPT_ENCODING, "gzip, deflate"); 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( self.set_header_if_none(
header::USER_AGENT, header::USER_AGENT,
concat!("Actix-web/", env!("CARGO_PKG_VERSION")), concat!("actix-web/", env!("CARGO_PKG_VERSION")),
); );
} }