pub fn error_page_middleware<S>(
    req: ServiceRequest,
    srv: &S,
) -> impl Future<Output = actix_web::Result<ServiceResponse>> + 'static
where
    S: Service<ServiceRequest, Response = ServiceResponse, Error = actix_web::Error>,
    S::Future: 'static,
{
    let fut = srv.call(req);

    async {
        let res = fut.await?;

        if (res.status().is_client_error() || res.status().is_server_error())
            && res.headers().get(header::CONTENT_TYPE).map(AsRef::as_ref)
                == Some(b"text/plain; charset=utf-8")
        {
            let req = res.request().clone();
            Ok(res.map_body(|head, body| map_error_page(&req, head, body)))
        } else {
            Ok(res)
        }
    }
}
/// Middleware to convert plain-text error responses to user-friendly web pages
Middleware to convert plain-text error responses to user-friendly web pages
Middleware to convert plain - text error responses to user - friendly web pages
pub fn error_page_middleware<S>(
    req: ServiceRequest,
    srv: &S,
) -> impl Future<Output = actix_web::Result<ServiceResponse>> + 'static
where
    S: Service<ServiceRequest, Response = ServiceResponse, Error = actix_web::Error>,
    S::Future: 'static,
{
    let fut = srv.call(req);
    async {
        let res = fut.await?;
        if (res.status().is_client_error() || res.status().is_server_error())
            && res.headers().get(header::CONTENT_TYPE).map(AsRef::as_ref)
                == Some(b"text/plain; charset=utf-8")
        {
            let req = res.request().clone();
            Ok(res.map_body(|head, body| map_error_page(&req, head, body)))
        } else {
            Ok(res)
        }
    }
}
pub fn error_page_middleware < S > ( req : ServiceRequest , srv : & S , ) -> impl Future < Output = actix_web :: Result < ServiceResponse > > + ' static where S : Service < ServiceRequest , Response = ServiceResponse , Error = actix_web :: Error > , S :: Future : ' static , { let fut = srv . call ( req ) ; async { let res = fut . await ? ; if ( res . status ( ) . is_client_error ( ) || res . status ( ) . is_server_error ( ) ) && res . headers ( ) . get ( header :: CONTENT_TYPE ) . map ( AsRef :: as_ref ) == Some ( b" " ) { let req = res . request ( ) . clone ( ) ; Ok ( res . map_body ( | head , body | map_error_page ( & req , head , body ) ) ) } else { Ok ( res ) } } }
Middleware to convert plain-text error responses to user-friendly web pages
Middleware to convert plain - text error responses to user - friendly web pages
req
ServiceRequest
srv
&S
req
ServiceRequest
srv
&S