Skip to content

Commit e8b524b

Browse files
ngickssbstp
authored andcommitted
Add Proxy-Authorization header if proxy_url has username
1 parent 4a0b6ee commit e8b524b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/streams.rs

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ use std::sync::mpsc;
1313
use std::thread;
1414
use std::time::Instant;
1515

16+
#[cfg(feature = "basic-auth")]
17+
use base64::Engine;
18+
1619
use url::{Host, Url};
1720

1821
use crate::happy;
@@ -91,6 +94,16 @@ impl BaseStream {
9194
write!(stream, "CONNECT {remote_host}:{remote_port} HTTP/1.1\r\n")?;
9295
write!(stream, "Host: {proxy_host}:{proxy_port}\r\n")?;
9396
write!(stream, "Connection: close\r\n")?;
97+
#[cfg(feature = "basic-auth")]
98+
if proxy_url.has_authority() {
99+
let username = proxy_url.username();
100+
let auth = match proxy_url.password() {
101+
Some(password) => format!("{username}:{password}"),
102+
None => format!("{username}:"),
103+
};
104+
let basic_auth = base64::engine::general_purpose::STANDARD.encode(auth);
105+
write!(stream, "Proxy-Authorization: Basic {basic_auth}\r\n")?;
106+
}
94107
write!(stream, "\r\n")?;
95108

96109
let mut stream = BufReaderWrite::new(stream);

0 commit comments

Comments
 (0)