fix: Dont send twice Host header when user provides it

This commit is contained in:
Σrebe - Romain GERARD 2023-10-26 18:23:54 +02:00
parent 7cafa674ba
commit ac0e946b23
No known key found for this signature in database
GPG key ID: 7A42B4B97E0332F4
2 changed files with 8 additions and 2 deletions

View file

@ -4,7 +4,7 @@ _default:
@just --list @just --list
make_release $VERSION: make_release $VERSION:
sed -ie 's/^version = .*/version = "'$VERSION'"/g' Cargo.toml sed -i 's/^version = .*/version = "'$VERSION'"/g' Cargo.toml
cargo fmt --all -- --check --color=always || (echo "Use cargo fmt to format your code"; exit 1) cargo fmt --all -- --check --color=always || (echo "Use cargo fmt to format your code"; exit 1)
cargo clippy --all --all-features -- -D warnings || (echo "Solve your clippy warnings to succeed"; exit 1) cargo clippy --all --all-features -- -D warnings || (echo "Solve your clippy warnings to succeed"; exit 1)
git add Cargo.* git add Cargo.*

View file

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