Struct aws_smithy_http_server::plugin::HttpPlugins

source ·
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>

source

pub fn new() -> Self

Create an empty HttpPlugins.

You can use HttpPlugins::push to add plugins to it.

source§

impl<P> HttpPlugins<P>

source

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
        }
    }
}
source

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>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for HttpPlugins<IdentityPlugin>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<CurrentPlugin> InstrumentExt<CurrentPlugin> for HttpPlugins<CurrentPlugin>

source§

fn instrument(self) -> HttpPlugins<PluginStack<InstrumentPlugin, CurrentPlugin>>

Applies an 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>

source§

impl<Ser, Op, T, InnerPlugin> Plugin<Ser, Op, T> for HttpPlugins<InnerPlugin>
where InnerPlugin: Plugin<Ser, Op, T>,

§

type Output = <InnerPlugin as Plugin<Ser, Op, T>>::Output

The type of the new Service.
source§

fn apply(&self, input: T) -> Self::Output

Maps a Service to another.
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more