Module rama::http::layer::set_status
Expand description
Middleware to override status codes.
§Example
use std::{iter::once, convert::Infallible};
use bytes::Bytes;
use rama_http::layer::set_status::SetStatusLayer;
use rama_http::{Body, Request, Response, StatusCode};
use rama_core::service::service_fn;
use rama_core::{Context, Layer, Service};
use rama_core::error::BoxError;
async fn handle(req: Request) -> Result<Response, Infallible> {
// ...
}
let mut service = (
// change the status to `404 Not Found` regardless what the inner service returns
SetStatusLayer::new(StatusCode::NOT_FOUND),
).layer(service_fn(handle));
// Call the service.
let request = Request::builder().body(Body::empty())?;
let response = service.serve(Context::default(), request).await?;
assert_eq!(response.status(), StatusCode::NOT_FOUND);
Structs§
- Middleware to override status codes.
- Layer that applies
SetStatus
which overrides the status codes.