Represents a chain of filters through which an HTTP request and response pass before reaching the final handler.
Each filter in the chain can:
- Inspect or modify the request and response
- Perform cross-cutting concerns (logging, authentication, validation, etc.)
- Short-circuit the request by not calling the next element in the chain
Calling next passes control to the next filter in the chain. If no filters remain, the request proceeds to the target handler.
Example
class LoggingFilter implements Filter {
@override
Future<void> doFilter(ServerHttpRequest request, ServerHttpResponse response, FilterChain chain) async {
print("Request URI: ${request.getRequestURI()}");
await chain.next(request, response); // continue the chain
print("Response status: ${response.getStatus()}");
}
}
class SecurityFilter extends OncePerRequestFilter {
@override
Future<void> doFilterInternal(ServerHttpRequest request, ServerHttpResponse response, FilterChain chain) async {
if (!request.hasValidToken()) {
response.setStatus(HttpStatus.UNAUTHORIZED);
return; // short-circuit
}
await chain.next(request, response);
}
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
next(
ServerHttpRequest request, ServerHttpResponse response) → Future< void> - Passes control to the next filter in the chain.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited