pub struct RedirectConfig {
pub max_redirects: usize,
pub same_origin_only: bool,
pub allowed_redirect_hosts: HashSet<String>,
pub strip_sensitive_headers: bool,
pub allow_https_downgrade: bool,
}Expand description
Configuration for redirect behavior
Controls how the HTTP client handles 3xx redirect responses with security protections.
§Security Features
- Same-origin enforcement: By default, only follows redirects to the same host
- Header stripping: Removes
Authorization,Cookieon cross-origin redirects - Downgrade protection: Blocks HTTPS → HTTP redirects
- Host allow-list: Configurable list of trusted redirect targets
§Example
use modkit_http::RedirectConfig;
use std::collections::HashSet;
// Permissive mode for general-purpose clients
let config = RedirectConfig::permissive();
// Custom allow-list for trusted hosts
let config = RedirectConfig {
same_origin_only: true,
allowed_redirect_hosts: HashSet::from(["cdn.example.com".to_string()]),
..Default::default()
};Fields§
§max_redirects: usizeMaximum number of redirects to follow (default: 10)
Set to 0 to disable redirect following entirely.
same_origin_only: boolOnly allow same-origin redirects (default: true)
When true, redirects to different hosts are blocked unless the target
host is in allowed_redirect_hosts.
Security: This is the safest default, preventing SSRF attacks where a malicious server redirects requests to internal services.
allowed_redirect_hosts: HashSet<String>Hosts that are allowed as redirect targets even when same_origin_only is true
Use this to allow redirects to known, trusted hosts (e.g., CDN domains, authentication servers).
Note: Entries should be hostnames only, without scheme or port.
Example: "cdn.example.com", not "https://cdn.example.com".
strip_sensitive_headers: boolStrip sensitive headers on cross-origin redirects (default: true)
When a redirect goes to a different origin (even if allowed), this removes:
Authorizationheader (prevents credential leakage)Cookieheader (prevents session hijacking)Proxy-Authorizationheader
Security: Always keep this enabled unless you have specific requirements.
allow_https_downgrade: boolAllow HTTPS → HTTP downgrades (default: false)
When false, redirects from HTTPS to HTTP are blocked.
Security: Downgrades expose traffic to interception. Only enable for testing with local mock servers.
Implementations§
Source§impl RedirectConfig
impl RedirectConfig
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a permissive configuration that allows all redirects with header stripping
This is suitable for general-purpose HTTP clients that need to follow redirects to any host, but still want protection against credential leakage.
Note: This configuration still blocks HTTPS → HTTP downgrades.
Sourcepub fn for_testing() -> Self
pub fn for_testing() -> Self
Create a configuration for testing (allows HTTP, permissive)
WARNING: Only use for local testing with mock servers.
Trait Implementations§
Source§impl Clone for RedirectConfig
impl Clone for RedirectConfig
Source§fn clone(&self) -> RedirectConfig
fn clone(&self) -> RedirectConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RedirectConfig
impl Debug for RedirectConfig
Auto Trait Implementations§
impl Freeze for RedirectConfig
impl RefUnwindSafe for RedirectConfig
impl Send for RedirectConfig
impl Sync for RedirectConfig
impl Unpin for RedirectConfig
impl UnwindSafe for RedirectConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
Source§fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
Source§fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
x-request-id as the header name. Read moreSource§fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
Source§fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
x-request-id as the header name. Read moreSource§fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
413 Payload Too Large responses. Read more