Expand description
Channel Security Module
Provides channel security enforcement including HTTPS redirection and port mapping. Similar to Spring Security’s channel security.
§Features
- HTTPS Enforcement: Redirect HTTP requests to HTTPS
- Port Mapping: Configure custom HTTP/HTTPS port mappings
- Path-based Rules: Apply different security to different paths
- Flexible Configuration: Customize redirect behavior
§Example
ⓘ
use actix_security::http::security::channel::{ChannelSecurity, ChannelSecurityConfig};
use actix_web::{App, HttpServer};
let channel_security = ChannelSecurity::new(
ChannelSecurityConfig::new()
.require_https(&["/login", "/api/**"])
.allow_http(&["/health", "/public/**"])
);
HttpServer::new(move || {
App::new()
.wrap(channel_security.clone())
// ... routes
})
.bind("0.0.0.0:80")?
.bind_rustls("0.0.0.0:443", config)?
.run()
.await§Spring Equivalent
http.requiresChannel()
.requestMatchers("/login", "/api/**").requiresSecure()
.requestMatchers("/public/**").requiresInsecure();Structs§
- Channel
Security - Channel security middleware
- Channel
Security Config - Configuration for channel security
- Channel
Security Service - Channel security service
- Port
Mapper - Port mapping for HTTP/HTTPS redirects
Enums§
- Channel
Requirement - Channel security requirement
Traits§
- Channel
Security Ext - Helper trait for building channel security rules