Struct actix_ip_filter::IPFilter[][src]

pub struct IPFilter { /* fields omitted */ }
Expand description

Middleware for filter IP of HTTP requests

Implementations

Construct IPFilter middleware with no arguments

Construct IPFilter middleware with the provided arguments and no limiting pattern.

Construct IPFilter middleware with the provided arguments and limiting patterns.

Use X-REAL-IP header to check IP if it is found in request.

Set allow IP list, it supported glob pattern. It will allow all if vec is empty.

Example
let middleware = IPFilter::new()
    .allow(vec!["127.??.6*.12", "!1.2.*.4'"]);

Set block IP list, it supported glob pattern.

Example
let middleware = IPFilter::new()
    .block(vec!["127.??.6*.12", "!1.2.*.4'"]);

Set endpoint limit list, supporting glob pattern.

Example
let middleware = IPFilter::new()
    .limit_to(vec!["/path/to/protected/resource*", "/protected/file/type/*.csv"]);

Add allow handler.

Example

fn my_custom_handler(filter: &IPFilter, ip: &str, req: &ServiceRequest) {
    // Do smth
}

let middleware = IPFilter::new()
    .on_allow(my_custom_handler);

Add block handler.

Example
use actix_web::error::ErrorForbidden;
use actix_web::HttpResponse;

fn my_custom_handler(filter: &IPFilter, ip: &str, req: &ServiceRequest) -> Option<HttpResponse> {
    Some(HttpResponse::Forbidden().body("My custom forbidden message!"))
}

let middleware = IPFilter::new()
    .on_block(my_custom_handler);

Trait Implementations

Returns the “default value” for a type. Read more

Responses produced by the service.

Errors produced by the service.

The TransformService value created by this factory

Errors produced while building a transform service.

The future response value.

Creates and returns a new Transform component, asynchronously

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more