pub trait ResponseValidator:
Send
+ Sync
+ 'static {
// Required method
fn validate(&self, head: Parts, body: Bytes) -> Result<(), ValidationError>;
}
Expand description
A validating utility for checking responses returned by the webserver are correct.
It’s important that these operations are light weight as they are called on the same runtime as the request runtime which may block operations.
§Example
This example is just the DefaultValidator implementation, it can do as much or as little as you’d like but it’s important that it does not block heavily as it will reduce the overall throughput of the worker thread.
use http::response::Parts;
use hyper::body::Bytes;
use rewrk_core::{ResponseValidator, ValidationError};
#[derive(Debug)]
pub struct DefaultValidator;
impl ResponseValidator for DefaultValidator {
fn validate(&self, head: Parts, _body: Bytes) -> Result<(), ValidationError> {
if head.status.is_success() {
Ok(())
} else {
Err(ValidationError::InvalidStatus(head.status.as_u16()))
}
}
}