diff options
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()); } |