Trait aws_smithy_http::middleware::MapRequest
source · pub trait MapRequest {
type Error: Into<Box<dyn Error + Send + Sync>>;
// Required methods
fn name(&self) -> &'static str;
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.
Examples
use http::header::{HeaderName, HeaderValue};
/// Signaling struct added to the request property bag if a header should be added
struct NeedsHeader;
struct AddHeader(HeaderName, HeaderValue);
impl MapRequest for AddHeader {
type Error = Infallible;
fn name(&self) -> &'static str {
"add_header"
}
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)
})
}
}