pub trait MapRequest {
    type Error: Into<Box<dyn Error + Send + Sync>>;
    fn apply(&self, request: Request) -> Result<Request, Self::Error>;
}
Expand description

MapRequest defines a synchronous middleware that transforms an operation::Request.

Typically, these middleware will read configuration from the PropertyBag and use it to augment the request. Most fundamental middleware is expressed as MapRequest, including signing & endpoint resolution.

use http::header::{HeaderName, HeaderValue};
struct AddHeader(HeaderName, HeaderValue);
/// Signaling struct added to the request property bag if a header should be added
struct NeedsHeader;
impl MapRequest for AddHeader {
    type Error = Infallible;
    fn apply(&self, request: operation::Request) -> Result<operation::Request, Self::Error> {
        request.augment(|mut request, properties| {
            if properties.get::<NeedsHeader>().is_some() {
                request.headers_mut().append(self.0.clone(), self.1.clone());
            }
            Ok(request)
        })
    }
}

Associated Types

The Error type returned by this operation.

If this middleware never fails use std::convert::Infallible or similar.

Required methods

Apply this middleware to a request.

Typically, implementations will use request.augment to be able to transform an owned http::Request.

Implementors