summaryrefslogtreecommitdiff
path: root/ext/fetch/proxy.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-07-24 22:22:43 +0100
committerGitHub <noreply@github.com>2024-07-24 23:22:43 +0200
commit1fad6eb2acc993714fad9d333f409495f5b3d6db (patch)
tree2b00c02b7306c7ad0577cd92e71fceba0a475475 /ext/fetch/proxy.rs
parentc7f468d33b5d0814b56036639eb2a8226d4bfbbf (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/fetch/proxy.rs')
-rw-r--r--ext/fetch/proxy.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/ext/fetch/proxy.rs b/ext/fetch/proxy.rs
index c8e54d5ec..bbb40e2f1 100644
--- a/ext/fetch/proxy.rs
+++ b/ext/fetch/proxy.rs
@@ -106,7 +106,7 @@ pub(crate) fn from_env() -> Proxies {
Proxies { intercepts, no }
}
-pub(crate) fn basic_auth(user: &str, pass: &str) -> HeaderValue {
+pub fn basic_auth(user: &str, pass: Option<&str>) -> HeaderValue {
use base64::prelude::BASE64_STANDARD;
use base64::write::EncoderWriter;
use std::io::Write;
@@ -114,7 +114,10 @@ pub(crate) fn basic_auth(user: &str, pass: &str) -> HeaderValue {
let mut buf = b"Basic ".to_vec();
{
let mut encoder = EncoderWriter::new(&mut buf, &BASE64_STANDARD);
- let _ = write!(encoder, "{user}:{pass}");
+ let _ = write!(encoder, "{user}:");
+ if let Some(password) = pass {
+ let _ = write!(encoder, "{password}");
+ }
}
let mut header =
HeaderValue::from_bytes(&buf).expect("base64 is always valid HeaderValue");
@@ -140,10 +143,10 @@ impl Intercept {
pub(crate) fn set_auth(&mut self, user: &str, pass: &str) {
match self.target {
Target::Http { ref mut auth, .. } => {
- *auth = Some(basic_auth(user, pass));
+ *auth = Some(basic_auth(user, Some(pass)));
}
Target::Https { ref mut auth, .. } => {
- *auth = Some(basic_auth(user, pass));
+ *auth = Some(basic_auth(user, Some(pass)));
}
Target::Socks { ref mut auth, .. } => {
*auth = Some((user.into(), pass.into()));
@@ -192,7 +195,7 @@ impl Target {
if is_socks {
socks_auth = Some((user.into(), pass.into()));
} else {
- http_auth = Some(basic_auth(user, pass));
+ http_auth = Some(basic_auth(user, Some(pass)));
}
builder = builder.authority(host_port);
} else {