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 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);
pub fn on_block(
self,
handler: fn(_: &Self, _: &str, _: &ServiceRequest) -> Option<HttpResponse>
) -> Self
pub fn on_block(
self,
handler: fn(_: &Self, _: &str, _: &ServiceRequest) -> Option<HttpResponse>
) -> Self
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
impl<S, B> Transform<S, ServiceRequest> for IPFilter where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
S::Future: 'static,
B: MessageBody + 'static,
impl<S, B> Transform<S, ServiceRequest> for IPFilter where
S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
S::Future: 'static,
B: MessageBody + 'static,
type Response = ServiceResponse<EitherBody<B>>
type Response = ServiceResponse<EitherBody<B>>
Responses produced by the service.
type Transform = IPFilterMiddleware<S>
type Transform = IPFilterMiddleware<S>
The TransformService
value created by this factory
Creates and returns a new Transform component, asynchronously
Auto Trait Implementations
impl RefUnwindSafe for IPFilter
impl UnwindSafe for IPFilter
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
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