Expand description
The HTTPS enforcement pipeline stage for tower stacks.
One tower::Layer answering the reference engine’s https_enforcement
check (guard_core/core/checks/implementations/https_enforcement.py)
before a request reaches the inner service.
The decision core is guard_core_engine::https_enforcement; this
stage wires it into the family’s tower seams:
route require_https wins over the global enforce_https arm
plain HTTP under a requirement: 301 redirect to the https URL
(the reference create_https_redirect)
passive mode: pass through (log-only in the reference)The reference answers the redirect through its response factory and the
response modifier, and never fires the block hook for this check
(https_enforcement is in ON_BLOCK_EXCLUDED_CHECK_NAMES) - the stage
mirrors the exclusion by construction (it carries no hook) and renders
the plain 301 + Location shape.
§Example
use guard_core_rs::https_enforcement::{HttpsEnforcementStage, HttpsEnforcementStageConfig};
let stage = HttpsEnforcementStage::builder(HttpsEnforcementStageConfig::default())
.enforce_https(true)
.build()
.expect("valid proxy list");
// Plain HTTP under a global enforcement: a 301 to the https URL.
let answer = stage
.decide("/", "http", None, None, "https://host.example/")
.expect("redirected");
assert_eq!(answer.status, 301);
assert_eq!(answer.location, "https://host.example/");
// HTTPS passes.
assert!(stage.decide("/", "https", None, None, "").is_none());Structs§
- Https
Enforcement Stage - The HTTPS enforcement stage.
- Https
Enforcement Stage Builder - Builder for
HttpsEnforcementStage. - Https
Enforcement Stage Config - The stage configuration (
SecurityConfig.enforce_https,.trust_x_forwarded_proto,.passive_mode). - Https
Enforcement Stage Layer - The
tower::LayercarryingHttpsEnforcementStage. - Https
Enforcement Stage Service - The stage as a
tower::Servicearound the inner service it wrapped. - Https
Redirect Answer - The stage’s answer: the reference’s
create_https_redirectshape (a301to the scheme-upgraded URL).
Constants§
- HTTPS_
ENFORCEMENT_ CHECK_ NAME - The check’s stable name (
check_name). - HTTPS_
REDIRECT_ STATUS - The redirect status the reference’s
create_https_redirectanswers with (create_redirect_response(https_url, 301)).
Type Aliases§
- Route
Https Resolver - How the stage learns a path’s
require_https(the reference reads it fromrequest.state.route_config).Nonemeans no route config: the global arm decides.Some(false)opts the route out.