From c4b2c65b5a86cdd2609b8c99b788a0299b3e01e1 Mon Sep 17 00:00:00 2001 From: Oliver Stenbom Date: Thu, 21 Dec 2023 14:58:24 +0000 Subject: [PATCH] Do not follow redirects on local linkup server (#53) This does not make it work when using a cloudflare worker / tunnel. The wasm client of reqwest does not support their "redirect policies" yet: https://github.com/seanmonstar/reqwest/blob/master/src/wasm/client.rs --- Cargo.lock | 2 +- linkup-cli/Cargo.toml | 2 +- linkup-cli/src/local_server.rs | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e94573b..2d47f2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1043,7 +1043,7 @@ dependencies = [ [[package]] name = "linkup-cli" -version = "0.2.3" +version = "0.2.4" dependencies = [ "actix-web", "clap", diff --git a/linkup-cli/Cargo.toml b/linkup-cli/Cargo.toml index 5e0c629..fab72f5 100644 --- a/linkup-cli/Cargo.toml +++ b/linkup-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "linkup-cli" -version = "0.2.3" +version = "0.2.4" edition = "2021" [[bin]] diff --git a/linkup-cli/src/local_server.rs b/linkup-cli/src/local_server.rs index 3152821..fa64488 100644 --- a/linkup-cli/src/local_server.rs +++ b/linkup-cli/src/local_server.rs @@ -89,7 +89,7 @@ async fn linkup_ws_request_handler( let extra_headers = get_additional_headers(&url, &headers, &session_name, &target_service); // Proxy the request using the destination_url and the merged headers - let client = reqwest::Client::new(); + let client = no_redirect_client(); headers.extend(&extra_headers); headers.remove(LinkupHeaderName::Host); @@ -193,7 +193,8 @@ async fn linkup_request_handler( let extra_headers = get_additional_headers(&url, &headers, &session_name, &target_service); // Proxy the request using the destination_url and the merged headers - let client = reqwest::Client::new(); + let client = no_redirect_client(); + headers.extend(&extra_headers); headers.remove(LinkupHeaderName::Host); @@ -250,6 +251,13 @@ async fn always_ok() -> impl Responder { HttpResponse::Ok().finish() } +fn no_redirect_client() -> reqwest::Client { + reqwest::Client::builder() + .redirect(reqwest::redirect::Policy::none()) + .build() + .unwrap() +} + #[actix_web::main] pub async fn local_linkup_main() -> io::Result<()> { env_logger::Builder::new()