From 70888cf3d6764c79554c1cc99de1a2197bec87b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=B0=8F=E7=99=BD?= <364772080@qq.com> Date: Fri, 17 May 2024 16:30:52 +0800 Subject: [PATCH] Fix `npm install` command with a `URI://localhost:port` proxy setting (#11955) NodeRuntime without environment information can not parse `localhost` correctly. Release Notes: - N/A --- crates/http/src/http.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/http/src/http.rs b/crates/http/src/http.rs index 2c1b879bdce98065c39c6f72e108bc0ef3fa693c..8ed208e37a622e6e99643d30a6f411b7e9a589a9 100644 --- a/crates/http/src/http.rs +++ b/crates/http/src/http.rs @@ -58,7 +58,15 @@ impl HttpClientWithUrl { /// Returns a new [`HttpClientWithUrl`] with the given base URL. pub fn new(base_url: impl Into, unparsed_proxy: Option) -> Self { let parsed_proxy = get_proxy(unparsed_proxy); - let proxy_string = parsed_proxy.as_ref().map(|p| p.to_string()); + let proxy_string = parsed_proxy.as_ref().map(|p| { + // Map proxy settings from `http://localhost:10809` to `http://127.0.0.1:10809` + // NodeRuntime without environment information can not parse `localhost` + // correctly. + // TODO: map to `[::1]` if we are using ipv6 + p.to_string() + .to_ascii_lowercase() + .replace("localhost", "127.0.0.1") + }); Self { base_url: Mutex::new(base_url.into()), client: client(parsed_proxy),