pub struct HttpPlugins<P>(/* private fields */);Expand description
A wrapper struct for composing HTTP plugins.
§Applying plugins in a sequence
You can use the push method to apply a new HTTP plugin after the ones that
have already been registered.
use aws_smithy_http_server::plugin::HttpPlugins;
let http_plugins = HttpPlugins::new().push(LoggingPlugin).push(MetricsPlugin);The plugins’ runtime logic is executed in registration order.
In our example above, LoggingPlugin would run first, while MetricsPlugin is executed last.
§Wrapping the current plugin pipeline
From time to time, you might have a need to transform the entire pipeline that has been built so far - e.g. you only want to apply those plugins for a specific operation.
HttpPlugins is itself a Plugin: you can apply any transformation that expects a
Plugin to an entire pipeline. In this case, we could use a scoped
plugin to limit the scope of the logging and metrics plugins to the
CheckHealth operation:
use aws_smithy_http_server::scope;
use aws_smithy_http_server::plugin::{HttpPlugins, Scoped};
use aws_smithy_http_server::shape_id::ShapeId;
// The logging and metrics plugins will only be applied to the `CheckHealth` operation.
let plugin = HttpPlugins::new()
.push(LoggingPlugin)
.push(MetricsPlugin);
scope! {
struct OnlyCheckHealth {
includes: [CheckHealth],
excludes: [/* The rest of the operations go here */]
}
}
let filtered_plugin = Scoped::new::<OnlyCheckHealth>(&plugin);
let http_plugins = HttpPlugins::new()
.push(filtered_plugin)
// The auth plugin will be applied to all operations.
.push(AuthPlugin);§Concatenating two collections of HTTP plugins
HttpPlugins is a good way to bundle together multiple plugins, ensuring they are all
registered in the correct order.
Since HttpPlugins is itself a HTTP plugin (it implements the HttpMarker trait), you can use
the push to append, at once, all the HTTP plugins in another
HttpPlugins to the current HttpPlugins:
use aws_smithy_http_server::plugin::{IdentityPlugin, HttpPlugins, PluginStack};
pub fn get_bundled_http_plugins() -> HttpPlugins<PluginStack<MetricsPlugin, PluginStack<LoggingPlugin, IdentityPlugin>>> {
HttpPlugins::new().push(LoggingPlugin).push(MetricsPlugin)
}
let http_plugins = HttpPlugins::new()
.push(AuthPlugin)
.push(get_bundled_http_plugins());§Providing custom methods on HttpPlugins
You use an extension trait to add custom methods on HttpPlugins.
This is a simple example using AuthPlugin:
use aws_smithy_http_server::plugin::{HttpPlugins, PluginStack};
pub trait AuthPluginExt<CurrentPlugins> {
fn with_auth(self) -> HttpPlugins<PluginStack<AuthPlugin, CurrentPlugins>>;
}
impl<CurrentPlugins> AuthPluginExt<CurrentPlugins> for HttpPlugins<CurrentPlugins> {
fn with_auth(self) -> HttpPlugins<PluginStack<AuthPlugin, CurrentPlugins>> {
self.push(AuthPlugin)
}
}
let http_plugins = HttpPlugins::new()
.push(LoggingPlugin)
// Our custom method!
.with_auth();Implementations§
Source§impl HttpPlugins<IdentityPlugin>
impl HttpPlugins<IdentityPlugin>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty HttpPlugins.
You can use HttpPlugins::push to add plugins to it.
Source§impl<P> HttpPlugins<P>
impl<P> HttpPlugins<P>
Sourcepub fn push<NewPlugin: HttpMarker>(
self,
new_plugin: NewPlugin,
) -> HttpPlugins<PluginStack<NewPlugin, P>>
pub fn push<NewPlugin: HttpMarker>( self, new_plugin: NewPlugin, ) -> HttpPlugins<PluginStack<NewPlugin, P>>
Apply a new HTTP plugin after the ones that have already been registered.
use aws_smithy_http_server::plugin::HttpPlugins;
let http_plugins = HttpPlugins::new().push(LoggingPlugin).push(MetricsPlugin);The plugins’ runtime logic is executed in registration order.
In our example above, LoggingPlugin would run first, while MetricsPlugin is executed last.
§Implementation notes
Plugins are applied to the underlying Service in opposite order compared
to their registration order.
As an example:
#[derive(Debug)]
pub struct PrintPlugin;
impl<Ser, Op, S> Plugin<Ser, Op, T> for PrintPlugin
// [...]
{
// [...]
fn apply(&self, inner: T) -> Self::Service {
PrintService {
inner,
service_id: Ser::ID,
operation_id: Op::ID
}
}
}Sourcepub fn layer<L>(self, layer: L) -> HttpPlugins<PluginStack<LayerPlugin<L>, P>>
pub fn layer<L>(self, layer: L) -> HttpPlugins<PluginStack<LayerPlugin<L>, P>>
Applies a single [tower::Layer] to all operations before they are deserialized.
Trait Implementations§
Source§impl<P: Debug> Debug for HttpPlugins<P>
impl<P: Debug> Debug for HttpPlugins<P>
Source§impl Default for HttpPlugins<IdentityPlugin>
impl Default for HttpPlugins<IdentityPlugin>
Source§impl<CurrentPlugin> InstrumentExt<CurrentPlugin> for HttpPlugins<CurrentPlugin>
impl<CurrentPlugin> InstrumentExt<CurrentPlugin> for HttpPlugins<CurrentPlugin>
Source§fn instrument(self) -> HttpPlugins<PluginStack<InstrumentPlugin, CurrentPlugin>>
fn instrument(self) -> HttpPlugins<PluginStack<InstrumentPlugin, CurrentPlugin>>
InstrumentOperation to every operation, respecting the @sensitive trait given on the input and
output models. See InstrumentOperation for more information.Source§impl<CurrentPlugin> OperationExtensionExt<CurrentPlugin> for HttpPlugins<CurrentPlugin>
impl<CurrentPlugin> OperationExtensionExt<CurrentPlugin> for HttpPlugins<CurrentPlugin>
Source§fn insert_operation_extension(
self,
) -> HttpPlugins<PluginStack<OperationExtensionPlugin, CurrentPlugin>>
fn insert_operation_extension( self, ) -> HttpPlugins<PluginStack<OperationExtensionPlugin, CurrentPlugin>>
Source§impl<Ser, Op, T, InnerPlugin> Plugin<Ser, Op, T> for HttpPlugins<InnerPlugin>where
InnerPlugin: Plugin<Ser, Op, T>,
impl<Ser, Op, T, InnerPlugin> Plugin<Ser, Op, T> for HttpPlugins<InnerPlugin>where
InnerPlugin: Plugin<Ser, Op, T>,
impl<InnerPlugin> HttpMarker for HttpPlugins<InnerPlugin>where
InnerPlugin: HttpMarker,
Auto Trait Implementations§
impl<P> Freeze for HttpPlugins<P>where
P: Freeze,
impl<P> RefUnwindSafe for HttpPlugins<P>where
P: RefUnwindSafe,
impl<P> Send for HttpPlugins<P>where
P: Send,
impl<P> Sync for HttpPlugins<P>where
P: Sync,
impl<P> Unpin for HttpPlugins<P>where
P: Unpin,
impl<P> UnwindSafe for HttpPlugins<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more