1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-04-16 14:54:15 +00:00

Fix ws client to upgrade with proper host headers

This commit is contained in:
Heinz Gies 2019-09-11 17:23:09 +02:00 committed by Heinz N. Gies
parent 06f98e64aa
commit 75b01c802c

View file

@ -234,10 +234,30 @@ impl WebsocketsRequest {
}
if !self.head.headers.contains_key(header::HOST) {
self.head.headers.insert(
header::HOST,
HeaderValue::from_str(uri.host().unwrap()).unwrap(),
);
let port = uri.port_u16();
let scheme = uri.scheme();
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
// requires us to include the port if it's not standard
let needs_port = ((scheme == Some("http") || scheme == Some("ws"))
&& port != Some(80))
|| ((scheme == Some("https") || scheme == Some("wss"))
&& port != Some(443));
if needs_port {
self.head.headers.insert(
header::HOST,
HeaderValue::from_str(&format!(
"{}:{}",
uri.host().unwrap(),
port.unwrap()
))
.unwrap(),
);
} else {
self.head.headers.insert(
header::HOST,
HeaderValue::from_str(uri.host().unwrap()).unwrap(),
);
};
}
// set cookies