-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Raymond Zhao <[email protected]>
- Loading branch information
Showing
9 changed files
with
339 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ pub mod config; | |
pub mod endpoints; | ||
pub mod io; | ||
pub mod middleware; | ||
mod proxy; | ||
mod retry; | ||
pub mod telemetry; |
44 changes: 44 additions & 0 deletions
44
lib/saluki-components/src/destinations/datadog/common/proxy.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use headers::Authorization; | ||
use http::Uri; | ||
use hyper_proxy2::{Intercept, Proxy}; | ||
use saluki_error::GenericError; | ||
use serde::Deserialize; | ||
use url::Url; | ||
|
||
#[derive(Clone, Deserialize)] | ||
pub struct ProxyConfiguration { | ||
/// The proxy server for HTTP requests. | ||
#[serde(rename = "proxy_http")] | ||
http_server: Option<String>, | ||
|
||
/// The proxy server for HTTPS requests. | ||
#[serde(rename = "proxy_https")] | ||
https_server: Option<String>, | ||
} | ||
|
||
impl ProxyConfiguration { | ||
/// Creates the list of proxies. | ||
pub fn build(&self) -> Result<Vec<Proxy>, GenericError> { | ||
let mut proxies = Vec::new(); | ||
if let Some(url) = &self.http_server { | ||
proxies.push(self.new_proxy(url, Intercept::Http)?); | ||
} | ||
if let Some(url) = &self.https_server { | ||
proxies.push(self.new_proxy(url, Intercept::Https)?); | ||
} | ||
Ok(proxies) | ||
} | ||
|
||
fn new_proxy(&self, url: &str, _intercept: Intercept) -> Result<Proxy, GenericError> { | ||
let url = Url::parse(url)?; | ||
let username = url.username(); | ||
let password = url.password().unwrap_or(""); | ||
let proxy_uri: Uri = url.as_str().parse()?; | ||
let mut proxy = hyper_proxy2::Proxy::new(Intercept::All, proxy_uri); | ||
if !username.is_empty() { | ||
let auth = Authorization::basic(username, password); | ||
proxy.set_authorization(auth); | ||
} | ||
Ok(proxy) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters