mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
Guide: additional tweaks to Middleware.
This commit is contained in:
parent
1a45dbd768
commit
e4a85a53f4
@ -1,8 +1,8 @@
|
||||
# Middleware
|
||||
|
||||
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
|
||||
as well as the ability to halt request processing and return response early.
|
||||
Middleware can hook into an incoming request process, enabling us to modify requests
|
||||
as well as halt request processing to return a response early.
|
||||
|
||||
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
|
||||
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
|
||||
# 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.
|
||||
|
||||
The `Logger` middleware uses the standard log crate to log information. You should enable logger
|
||||
for *actix_web* package to see access log
|
||||
([env_logger](https://docs.rs/env_logger/*/env_logger/) or similar).
|
||||
for *actix_web* package to see access log ([env_logger](https://docs.rs/env_logger/*/env_logger/)
|
||||
or similar).
|
||||
|
||||
### Usage
|
||||
|
||||
@ -219,7 +219,7 @@ fn main() {
|
||||
`ErrorHandlers` middleware allows us to provide custom handlers for responses.
|
||||
|
||||
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
|
||||
into a response.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user