Skip to content

Commit 491b5cf

Browse files
authored
feat: Add proxy support including HTTP_PROXY, HTTPS_PROXY detection (#115)
This commit introduces proxy handling functionality for the hyper transport, including automatic instrumentation through environment variables. If HTTPS_PROXY is defined, all HTTPS traffic will potentially be routed through this proxy. If HTTP_PROXY is ALSO specified, then HTTP traffic will be routed through it. However, if HTTP_PROXY is specified without HTTPS_PROXY, then all traffic (http and https) will be routed through the HTTP_PROXY.
1 parent 0ea657c commit 491b5cf

5 files changed

Lines changed: 285 additions & 121 deletions

File tree

contract-tests/src/bin/sse-test-api/stream_entity.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ impl Inner {
131131
transport_builder = transport_builder.read_timeout(Duration::from_millis(timeout_ms));
132132
}
133133

134-
let transport = transport_builder.build_https();
134+
let transport = transport_builder
135+
.build_https()
136+
.map_err(|e| format!("Failed to build HTTPS transport: {e:?}"))?;
135137

136138
Ok(Box::new(
137139
client_builder

eventsource-client/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ base64 = "0.22.1"
2626
hyper = { version = "1.0", features = ["client", "http1", "http2"], optional = true }
2727
hyper-util = { version = "0.1", features = ["client-legacy", "http1", "http2", "tokio"], optional = true }
2828
http-body-util = { version = "0.1", optional = true }
29+
hyper-http-proxy = { version = "1.1.0", optional = true }
2930
hyper-rustls = { version = "0.27", default-features = false, features = ["http1", "http2", "native-tokio", "ring", "tls12", "webpki-roots"], optional = true }
3031
hyper-timeout = { version = "0.5", optional = true }
3132
tower = { version = "0.4", optional = true }
33+
no-proxy = { version = "0.3.6", default-features = false }
3234

3335
[dev-dependencies]
3436
env_logger = "0.10.0"
@@ -41,5 +43,5 @@ proptest = "1.0.0"
4143

4244
[features]
4345
default = ["hyper"]
44-
hyper = ["dep:hyper", "dep:hyper-util", "dep:http-body-util", "dep:hyper-timeout", "dep:tower"]
46+
hyper = ["dep:hyper", "dep:hyper-util", "dep:http-body-util", "dep:hyper-timeout", "dep:tower", "dep:hyper-http-proxy"]
4547
hyper-rustls = ["hyper", "dep:hyper-rustls"]

eventsource-client/examples/tail.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async fn run_with_http(url: &str, auth_header: &str) -> Result<(), Box<dyn std::
5959
let transport = es::HyperTransport::builder()
6060
.connect_timeout(Duration::from_secs(10))
6161
.read_timeout(Duration::from_secs(30))
62-
.build_http();
62+
.build_http()?;
6363

6464
let client = es::ClientBuilder::for_url(url)?
6565
.header("Authorization", auth_header)?
@@ -85,7 +85,7 @@ async fn run_with_https(url: &str, auth_header: &str) -> Result<(), Box<dyn std:
8585
let transport = es::HyperTransport::builder()
8686
.connect_timeout(Duration::from_secs(10))
8787
.read_timeout(Duration::from_secs(30))
88-
.build_https();
88+
.build_https()?;
8989

9090
let client = es::ClientBuilder::for_url(url)?
9191
.header("Authorization", auth_header)?

eventsource-client/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ mod event_parser;
5757
mod response;
5858
mod retry;
5959
mod transport;
60+
6061
#[cfg(feature = "hyper")]
6162
mod transport_hyper;
6263

0 commit comments

Comments
 (0)