mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
Guide: additional tweaks to Middleware.
This commit is contained in:
parent
1a45dbd768
commit
e4a85a53f4
@ -1,8 +1,8 @@
|
|||||||
# Middleware
|
# Middleware
|
||||||
|
|
||||||
Actix's middleware system allows us to add additional behavior to request/response processing.
|
Actix's middleware system allows us to add additional behavior to request/response processing.
|
||||||
Middleware can hook into an incoming request process, enabling the ability to modify requests
|
Middleware can hook into an incoming request process, enabling us to modify requests
|
||||||
as well as the ability to halt request processing and return response early.
|
as well as halt request processing to return a response early.
|
||||||
|
|
||||||
Middleware can also hook into response processing.
|
Middleware can also hook into response processing.
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ registration. In general, a *middleware* is a type that implements the
|
|||||||
in this trait has a default implementation. Each method can return a result immediately
|
in this trait has a default implementation. Each method can return a result immediately
|
||||||
or a *future* object.
|
or a *future* object.
|
||||||
|
|
||||||
The following is an example of a simple middleware that adds request and response headers:
|
The following demonstrates using middleware to add request and response headers:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
# extern crate http;
|
# extern crate http;
|
||||||
@ -68,8 +68,8 @@ It is common to register a logging middleware as the first middleware for the ap
|
|||||||
Logging middleware must be registered for each application.
|
Logging middleware must be registered for each application.
|
||||||
|
|
||||||
The `Logger` middleware uses the standard log crate to log information. You should enable logger
|
The `Logger` middleware uses the standard log crate to log information. You should enable logger
|
||||||
for *actix_web* package to see access log
|
for *actix_web* package to see access log ([env_logger](https://docs.rs/env_logger/*/env_logger/)
|
||||||
([env_logger](https://docs.rs/env_logger/*/env_logger/) or similar).
|
or similar).
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
@ -219,7 +219,7 @@ fn main() {
|
|||||||
`ErrorHandlers` middleware allows us to provide custom handlers for responses.
|
`ErrorHandlers` middleware allows us to provide custom handlers for responses.
|
||||||
|
|
||||||
You can use the `ErrorHandlers::handler()` method to register a custom error handler
|
You can use the `ErrorHandlers::handler()` method to register a custom error handler
|
||||||
for specific status code. You can modify an existing response or create completly new
|
for a specific status code. You can modify an existing response or create a completly new
|
||||||
one. The error handler can return a response immediately or return a future that resolves
|
one. The error handler can return a response immediately or return a future that resolves
|
||||||
into a response.
|
into a response.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user