Skip to content

Commit

Permalink
Add Proxy Support (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
visig9 authored Aug 11, 2024
1 parent 7aa756a commit 9659fae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ rustls-tls = ["reqwest/rustls-tls", "graph-http/rustls-tls", "graph-oauth/rustls
brotli = ["reqwest/brotli", "graph-http/brotli", "graph-oauth/brotli", "graph-core/brotli"]
deflate = ["reqwest/deflate", "graph-http/deflate", "graph-oauth/deflate", "graph-core/deflate"]
trust-dns = ["reqwest/trust-dns", "graph-http/trust-dns", "graph-oauth/trust-dns", "graph-core/trust-dns"]
socks = ["graph-http/socks"]
openssl = ["graph-oauth/openssl"]
interactive-auth = ["graph-oauth/interactive-auth"]
test-util = ["graph-http/test-util"]
Expand Down
1 change: 1 addition & 0 deletions graph-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ rustls-tls = ["reqwest/rustls-tls", "graph-core/rustls-tls"]
brotli = ["reqwest/brotli", "graph-core/brotli"]
deflate = ["reqwest/deflate", "graph-core/deflate"]
trust-dns = ["reqwest/trust-dns", "graph-core/trust-dns"]
socks = ["reqwest/socks"]
test-util = []
20 changes: 20 additions & 0 deletions graph-http/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use graph_core::identity::{ClientApplication, ForceTokenRefresh};
use reqwest::header::{HeaderMap, HeaderValue, ACCEPT, USER_AGENT};
use reqwest::redirect::Policy;
use reqwest::tls::Version;
use reqwest::Proxy;
use std::env::VarError;
use std::ffi::OsStr;
use std::fmt::{Debug, Formatter};
Expand All @@ -25,6 +26,7 @@ struct ClientConfiguration {
/// TLS 1.2 required to support all features in Microsoft Graph
/// See [Reliability and Support](https://learn.microsoft.com/en-us/graph/best-practices-concept#reliability-and-support)
min_tls_version: Version,
proxy: Option<Proxy>,
}

impl ClientConfiguration {
Expand All @@ -45,6 +47,7 @@ impl ClientConfiguration {
connection_verbose: false,
https_only: true,
min_tls_version: Version::TLS_1_2,
proxy: None,
}
}
}
Expand All @@ -58,6 +61,7 @@ impl Debug for ClientConfiguration {
.field("connect_timeout", &self.connect_timeout)
.field("https_only", &self.https_only)
.field("min_tls_version", &self.min_tls_version)
.field("proxy", &self.proxy)
.finish()
}
}
Expand Down Expand Up @@ -146,6 +150,14 @@ impl GraphClientConfiguration {
self
}

/// Set [`Proxy`] for all network operations.
///
/// Default is no proxy.
pub fn proxy(mut self, proxy: Proxy) -> GraphClientConfiguration {
self.config.proxy = Some(proxy);
self
}

#[cfg(feature = "test-util")]
pub fn https_only(mut self, https_only: bool) -> GraphClientConfiguration {
self.config.https_only = https_only;
Expand All @@ -171,6 +183,10 @@ impl GraphClientConfiguration {
builder = builder.connect_timeout(connect_timeout);
}

if let Some(proxy) = self.config.proxy {
builder = builder.proxy(proxy);
}

if let Some(client_application) = self.config.client_application {
Client {
client_application,
Expand Down Expand Up @@ -206,6 +222,10 @@ impl GraphClientConfiguration {
builder = builder.connect_timeout(connect_timeout);
}

if let Some(proxy) = self.config.proxy {
builder = builder.proxy(proxy);
}

if let Some(client_application) = self.config.client_application {
BlockingClient {
client_application,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ pub mod http {

pub use reqwest::tls::Version;
pub use reqwest::{Body, Method};
pub use reqwest::{NoProxy, Proxy};
pub use url::Url;
}

Expand Down

0 comments on commit 9659fae

Please sign in to comment.