From 1fad6eb2acc993714fad9d333f409495f5b3d6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 24 Jul 2024 22:22:43 +0100 Subject: fix(ext/fetch): respect authority from URL (#24705) This commit fixes handling of "authority" in the URL by properly sending "Authorization Basic..." header in `fetch` API. This is a regression from https://github.com/denoland/deno/pull/24593 Fixes https://github.com/denoland/deno/issues/24697 CC @seanmonstar --- ext/node/ops/http.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ext/node') diff --git a/ext/node/ops/http.rs b/ext/node/ops/http.rs index 89024e3f3..19847820e 100644 --- a/ext/node/ops/http.rs +++ b/ext/node/ops/http.rs @@ -18,6 +18,7 @@ use deno_fetch::ResourceToBodyAdapter; use http::header::HeaderMap; use http::header::HeaderName; use http::header::HeaderValue; +use http::header::AUTHORIZATION; use http::header::CONTENT_LENGTH; use http::Method; use http_body_util::BodyExt; @@ -43,7 +44,8 @@ where }; let method = Method::from_bytes(&method)?; - let url = Url::parse(&url)?; + let mut url = Url::parse(&url)?; + let maybe_authority = deno_fetch::extract_authority(&mut url); { let permissions = state.borrow_mut::

(); @@ -89,6 +91,12 @@ where .map_err(|_| type_error("Invalid URL"))?; *request.headers_mut() = header_map; + if let Some((username, password)) = maybe_authority { + request.headers_mut().insert( + AUTHORIZATION, + deno_fetch::basic_auth(&username, password.as_deref()), + ); + } if let Some(len) = con_len { request.headers_mut().insert(CONTENT_LENGTH, len.into()); } -- cgit v1.2.3