From ac0e946b23e1eeddf01fd7dab0871e4963449cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Thu, 26 Oct 2023 18:23:54 +0200 Subject: [PATCH] fix: Dont send twice Host header when user provides it --- justfile | 2 +- src/tunnel/client.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index a6cc1f5..3bb7e6f 100644 --- a/justfile +++ b/justfile @@ -4,7 +4,7 @@ _default: @just --list 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 clippy --all --all-features -- -D warnings || (echo "Solve your clippy warnings to succeed"; exit 1) git add Cargo.* diff --git a/src/tunnel/client.rs b/src/tunnel/client.rs index 83dde28..8ad8d77 100644 --- a/src/tunnel/client.rs +++ b/src/tunnel/client.rs @@ -58,16 +58,22 @@ pub async fn connect( &client_cfg.http_upgrade_path_prefix, jsonwebtoken::encode(alg, &data, secret).unwrap_or_default(), )) - .header(HOST, client_cfg.remote_addr.0.to_string()) .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()); + } if let Some(auth) = &client_cfg.http_upgrade_credentials { req = req.header(AUTHORIZATION, auth.clone()); }