From 8d61fe09257a2439a00c737728f6a26a5111c1cb Mon Sep 17 00:00:00 2001 From: Eugene Bulkin Date: Mon, 9 Sep 2019 01:27:13 -0500 Subject: [PATCH] Ensure that awc::ws::WebsocketsRequest sets the Host header (#1070) * Ensure that awc::ws::WebsocketsRequest sets the Host header before connecting. * Make sure to check if headers already have a HOST value before setting * Update CHANGES.md to reflect WebSocket client update. --- awc/CHANGES.md | 6 ++++++ awc/src/ws.rs | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/awc/CHANGES.md b/awc/CHANGES.md index 5edfc5e38..5442e9dbd 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -1,5 +1,11 @@ # Changes +## [0.2.5] - 2019-09-06 + +### Changed + +* Ensure that the `Host` header is set when initiating a WebSocket client connection. + ## [0.2.4] - 2019-08-13 ### Changed diff --git a/awc/src/ws.rs b/awc/src/ws.rs index 72c9a38bc..67be9e9d8 100644 --- a/awc/src/ws.rs +++ b/awc/src/ws.rs @@ -233,6 +233,10 @@ impl WebsocketsRequest { return Either::A(err(InvalidUrl::UnknownScheme.into())); } + if !self.head.headers.contains_key(header::HOST) { + self.head.headers.insert(header::HOST, HeaderValue::from_str(uri.host().unwrap()).unwrap()); + } + // set cookies if let Some(ref mut jar) = self.cookies { let mut cookie = String::new();