# actix_web::middleware::Middleware - Rust
API documentation for the Rust `Middleware` trait in crate `actix_web`.
Keywords: rust, rustlang, rust-lang, Middleware

# [−] [src] Trait actix_web::middleware::Middleware

    pub trait Middleware<S>: 'static {
        fn start(&self, req: &HttpRequest<S>) -> Result<Started> { ... }
        fn response(
            &self,
            req: &HttpRequest<S>,
            resp: HttpResponse
        ) -> Result<Response> { ... }
        fn finish(&self, req: &HttpRequest<S>, resp: &HttpResponse) -> Finished { ... }
    }

Middleware definition

## Provided Methods

### `fn start(&self, req: &HttpRequest<S>) -> Result<Started>`

Method is called when request is ready. It may return future, which should resolve before next middleware get called.

### `fn response(&self, req: &HttpRequest<S>, resp: HttpResponse) -> Result<Response>`

Method is called when handler returns response, but before sending http message to peer.

### `fn finish(&self, req: &HttpRequest<S>, resp: &HttpResponse) -> Finished`

Method is called after body stream get sent to peer.

## Implementors

###

`impl<S> Middleware<S> for Cors`

[src]

####

`fn start(&self, req: &HttpRequest<S>) -> Result<Started>`

[src]

####

`fn response(&self, req: &HttpRequest<S>, resp: HttpResponse) -> Result<Response>`

[src]

####

`fn finish(&self, req: &HttpRequest<S>, resp: &HttpResponse) -> Finished`

[src]

###

`impl<S> Middleware<S> for CsrfFilter`

[src]

####

`fn start(&self, req: &HttpRequest<S>) -> Result<Started>`

[src]

####

`fn response(&self, req: &HttpRequest<S>, resp: HttpResponse) -> Result<Response>`

[src]

####

`fn finish(&self, req: &HttpRequest<S>, resp: &HttpResponse) -> Finished`

[src]

###

`impl<S> Middleware<S> for DefaultHeaders`

[src]

####

`fn response(&self, _: &HttpRequest<S>, resp: HttpResponse) -> Result<Response>`

[src]

####

`fn start(&self, req: &HttpRequest<S>) -> Result<Started>`

[src]

####

`fn finish(&self, req: &HttpRequest<S>, resp: &HttpResponse) -> Finished`

[src]

###

`impl<S> Middleware<S> for Logger`

[src]

####

`fn start(&self, req: &HttpRequest<S>) -> Result<Started>`

[src]

####

`fn finish(&self, req: &HttpRequest<S>, resp: &HttpResponse) -> Finished`

[src]

####

`fn response(&self, req: &HttpRequest<S>, resp: HttpResponse) -> Result<Response>`

[src]

###

`impl<S: 'static> Middleware<S> for ErrorHandlers<S>`

[src]

####

`fn response(&self, req: &HttpRequest<S>, resp: HttpResponse) -> Result<Response>`

[src]

####

`fn start(&self, req: &HttpRequest<S>) -> Result<Started>`

[src]

####

`fn finish(&self, req: &HttpRequest<S>, resp: &HttpResponse) -> Finished`

[src]

###

`impl<S: 'static, T: IdentityPolicy<S>> Middleware<S> for IdentityService<T>`

[src]

####

`fn start(&self, req: &HttpRequest<S>) -> Result<Started>`

[src]

####

`fn response(&self, req: &HttpRequest<S>, resp: HttpResponse) -> Result<Response>`

[src]

####

`fn finish(&self, req: &HttpRequest<S>, resp: &HttpResponse) -> Finished`

[src]

###

`impl<S: 'static, T: SessionBackend<S>> Middleware<S> for SessionStorage<T, S>`

[src]

####

`fn start(&self, req: &HttpRequest<S>) -> Result<Started>`

[src]

####

`fn response(&self, req: &HttpRequest<S>, resp: HttpResponse) -> Result<Response>`

[src]

####

`fn finish(&self, req: &HttpRequest<S>, resp: &HttpResponse) -> Finished`

[src]

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)