Rust

redirect

Module

The redirect policy: when a response is a redirect, where it leads (RFC 3986 reference resolution) and which credentials it may carry there.

Contents

use utopia_client::redirect::is_redirect;
Rust
pub fn is_redirect(response: &Response) -> bool

Whether a response is a redirect to follow: a 3xx status with a non-empty Location.

use utopia_client::redirect::is_same_origin;
Rust
pub fn is_same_origin(from: &Uri, to: &Uri) -> bool

Whether two URIs share an origin: scheme, host and port (the scheme's default when absent), compared case-insensitively.

use utopia_client::redirect::remove_dot_segments;
Rust
pub fn remove_dot_segments(path: &str) -> String

RFC 3986 §5.2.4 remove_dot_segments.

use utopia_client::redirect::resolve;
Rust
pub fn resolve(base: &Uri, location: &str) -> Result<Uri, Error>

Resolves a Location against the URI it was received for (RFC 3986 §5.2), removing dot segments.

Fails with Error::InvalidArgument (Invalid URI.) when the location does not parse.

Rust
use utopia_client::{redirect, Uri};

let base = Uri::parse("https://example.com/a/b/c?q=1")?;
assert_eq!(redirect::resolve(&base, "../d")?.to_string(), "https://example.com/a/d");
assert_eq!(redirect::resolve(&base, "//cdn.example.com/x")?.to_string(), "https://cdn.example.com/x");
assert_eq!(redirect::resolve(&base, "#top")?.to_string(), "https://example.com/a/b/c?q=1#top");
use utopia_client::redirect::should_strip_sensitive_headers;
Rust
pub fn should_strip_sensitive_headers(from: &Uri, to: &Uri) -> bool

Whether a hop from from to to must drop credentials: whenever the origin changes, so an HTTPS to HTTP hop on the same host too.

use utopia_client::redirect::without_sensitive_headers;
Rust
pub fn without_sensitive_headers(headers: &mut Headers)

Removes Authorization, Cookie, Cookie2 and Proxy-Authorization.

Rust
pub const MAX_HOPS: u32 = 50

The most redirects a request follows by default.