diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-07-24 22:22:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-24 23:22:43 +0200 |
commit | 1fad6eb2acc993714fad9d333f409495f5b3d6db (patch) | |
tree | 2b00c02b7306c7ad0577cd92e71fceba0a475475 /ext/node/ops/http.rs | |
parent | c7f468d33b5d0814b56036639eb2a8226d4bfbbf (diff) |
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
Diffstat (limited to 'ext/node/ops/http.rs')
-rw-r--r-- | ext/node/ops/http.rs | 10 |
1 files changed, 9 insertions, 1 deletions
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::<P>(); @@ -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()); } |