Skip to main content

Module channel

Module channel 

Source
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§

ChannelSecurity
Channel security middleware
ChannelSecurityConfig
Configuration for channel security
ChannelSecurityService
Channel security service
PortMapper
Port mapping for HTTP/HTTPS redirects

Enums§

ChannelRequirement
Channel security requirement

Traits§

ChannelSecurityExt
Helper trait for building channel security rules