Skip to content

Commit

Permalink
pass through proxy auth
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 16, 2024
1 parent 202571c commit e4226aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions iroh-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = tr
iroh-metrics = { version = "0.16.0", path = "../iroh-metrics", default-features = false }
strum = { version = "0.26.2", features = ["derive"] }
pin-project-lite = "0.2.14"
base64 = "0.22.1"

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
netlink-packet-core = "0.7.0"
Expand Down
22 changes: 19 additions & 3 deletions iroh-net/src/relay/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::net::{IpAddr, SocketAddr};
use std::sync::Arc;
use std::time::Duration;

use base64::{engine::general_purpose::URL_SAFE, Engine as _};
use bytes::Bytes;
use futures_lite::future::Boxed as BoxFuture;
use http_body_util::Empty;
Expand Down Expand Up @@ -882,12 +883,27 @@ impl Actor {
url_port(&self.url).ok_or_else(|| ClientError::Proxy("invalid target port".into()))?;

// Establish Proxy Tunnel
let req = Request::builder()
let mut req_builder = Request::builder()
.uri(format!("{}:{}", target_host, port))
.method("CONNECT")
.header("Host", target_host)
.header("Proxy-Connection", "Keep-Alive")
.body(Empty::<Bytes>::new())?;
.header("Proxy-Connection", "Keep-Alive");
if !proxy_url.username().is_empty() {
// Passthrough authorization
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization
debug!(
"setting proxy-authorization: username={}",
proxy_url.username()
);
let to_encode = format!(
"{}:{}",
proxy_url.username(),
proxy_url.password().unwrap_or_default()
);
let encoded = URL_SAFE.encode(&to_encode);
req_builder = req_builder.header("Proxy-Authorization", format!("Basic {}", encoded));
}
let req = req_builder.body(Empty::<Bytes>::new())?;

debug!("Sending proxy request: {:?}", req);

Expand Down

0 comments on commit e4226aa

Please sign in to comment.