mirror of https://github.com/fafhrd91/actix-web
Fix ws client to upgrade with proper host headers
This commit is contained in:
parent
06f98e64aa
commit
75b01c802c
|
@ -234,10 +234,30 @@ impl WebsocketsRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.head.headers.contains_key(header::HOST) {
|
if !self.head.headers.contains_key(header::HOST) {
|
||||||
self.head.headers.insert(
|
let port = uri.port_u16();
|
||||||
header::HOST,
|
let scheme = uri.scheme();
|
||||||
HeaderValue::from_str(uri.host().unwrap()).unwrap(),
|
// 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
|
// set cookies
|
||||||
|
|
Loading…
Reference in New Issue