Module filter

Module filter 

Source
Expand description

Request filtering module that provides composable request filters.

This module implements a filter system that allows you to:

  • Filter requests based on HTTP methods
  • Filter requests based on headers
  • Combine multiple filters using AND/OR logic
  • Create custom filters using closures

§Thread Safety

All filters must implement the Filter trait, which requires Send + Sync. This ensures that filters can be safely shared and used across threads, which is essential for concurrent request handling in a web server environment.

§Examples

use micro_web::router::filter::{all_filter, any_filter, get_method, header};

// Create a filter that matches GET requests
let get_filter = get_method();

// Create a filter that checks for specific header
let auth_filter = header("Authorization", "Bearer token");

// Combine filters with AND logic
let mut combined = all_filter();
combined.and(get_filter).and(auth_filter);

Structs§

AllFilter
Compose filters with AND logic.
AnyFilter
Compose filters with OR logic.
FalseFilter
A filter that always returns false.
HeaderFilter
A filter that matches HTTP headers.
MethodFilter
A filter that matches HTTP methods.
TrueFilter
A filter that always returns true.

Traits§

Filter
Core trait for request filtering.

Functions§

all_filter
Creates a new AND-composed filter chain.
any_filter
Creates a new OR-composed filter chain.
connect_method
Creates a filter that matches HTTP CONNECT requests.
delete_method
Creates a filter that matches HTTP DELETE requests.
false_filter
Creates a filter that always returns false.
filter_fn
Creates a new filter from a closure.
get_method
Creates a filter that matches HTTP GET requests.
head_method
Creates a filter that matches HTTP HEAD requests.
header
Creates a filter that matches a specific header name and value.
options_method
Creates a filter that matches HTTP OPTIONS requests.
patch_method
Creates a filter that matches HTTP PATCH requests.
post_method
Creates a filter that matches HTTP POST requests.
put_method
Creates a filter that matches HTTP PUT requests.
trace_method
Creates a filter that matches HTTP TRACE requests.
true_filter
Creates a filter that always returns true.