Create new configuration option for redirect preserving authorization header in Agent. Handle new option in Unit
This commit is contained in:
21
src/agent.rs
21
src/agent.rs
@@ -16,6 +16,16 @@ use {
|
||||
cookie_store::CookieStore,
|
||||
};
|
||||
|
||||
/// Specify the strategy for propagation of authorization headers during Redirects
|
||||
///
|
||||
/// Never is the default strategy and never send authorization headers in Redirects
|
||||
/// SameHost send the authorization header in Redirects only if the host of the Redirect is the same of the previous request, and both use the Https scheme
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum RedirectAuthHeaders {
|
||||
Never,
|
||||
SameHost,
|
||||
}
|
||||
|
||||
/// Accumulates options towards building an [Agent].
|
||||
#[derive(Debug)]
|
||||
pub struct AgentBuilder {
|
||||
@@ -38,6 +48,7 @@ pub(crate) struct AgentConfig {
|
||||
pub timeout_write: Option<Duration>,
|
||||
pub timeout: Option<Duration>,
|
||||
pub redirects: u32,
|
||||
pub redirect_auth_headers: RedirectAuthHeaders,
|
||||
pub user_agent: String,
|
||||
pub tls_config: Arc<dyn TlsConnector>,
|
||||
}
|
||||
@@ -221,6 +232,7 @@ impl AgentBuilder {
|
||||
timeout_write: None,
|
||||
timeout: None,
|
||||
redirects: 5,
|
||||
redirect_auth_headers: RedirectAuthHeaders::Never,
|
||||
user_agent: format!("ureq/{}", env!("CARGO_PKG_VERSION")),
|
||||
tls_config: crate::default_tls_config(),
|
||||
},
|
||||
@@ -445,6 +457,15 @@ impl AgentBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the strategy for propagation of authorization headers in redirects.
|
||||
///
|
||||
/// Defaults to RedirectAuthHeaders::Never.
|
||||
///
|
||||
pub fn set_redirect_auth_headers(mut self, v: RedirectAuthHeaders) -> Self {
|
||||
self.config.redirect_auth_headers = v;
|
||||
self
|
||||
}
|
||||
|
||||
/// The user-agent header to associate with all requests from this agent by default.
|
||||
///
|
||||
/// Defaults to `ureq/[VERSION]`. You can override the user-agent on an individual request by
|
||||
|
||||
Reference in New Issue
Block a user