Prepare host header ahead of time

This commit is contained in:
Σrebe - Romain GERARD 2023-10-26 22:04:41 +02:00
parent 79632bb058
commit f813d925d6
No known key found for this signature in database
GPG key ID: 7A42B4B97E0332F4
2 changed files with 21 additions and 13 deletions

View file

@ -58,24 +58,18 @@ pub async fn connect(
&client_cfg.http_upgrade_path_prefix,
jsonwebtoken::encode(alg, &data, secret).unwrap_or_default(),
))
.header(HOST, &client_cfg.host_http_header)
.header(UPGRADE, "websocket")
.header(CONNECTION, "upgrade")
.header(SEC_WEBSOCKET_KEY, fastwebsockets::handshake::generate_key())
.header(SEC_WEBSOCKET_VERSION, "13")
.version(hyper::Version::HTTP_11);
let mut contains_host = false;
for (k, v) in &client_cfg.http_headers {
if k == HOST.as_str() {
contains_host = true;
}
req = req.header(k.clone(), v.clone());
}
if !contains_host {
req = req.header(HOST, client_cfg.remote_addr.0.to_string());
req = req.header(k, v);
}
if let Some(auth) = &client_cfg.http_upgrade_credentials {
req = req.header(AUTHORIZATION, auth.clone());
req = req.header(AUTHORIZATION, auth);
}
let req = req.body(Body::empty()).with_context(|| {