RequestPlugins

Struct RequestPlugins 

Source
pub struct RequestPlugins { /* private fields */ }
Expand description

The per-request plugin execution state (DW-157): the unified chain plus the fail-closed helpers that drive it. Constructed by RequestPlugins::build only on routes that reference plugins; Drop runs the on_done cleanup callback on every exit path (early short-circuits, failures, and the natural tail alike).

Implementations§

Source§

impl RequestPlugins

Source

pub fn build( lifecycle: &PluginLifecycle, configs: &HashMap<String, PluginConfig>, registry: &NativeRegistry, route: &Route, obs: &Observability, rid: &str, ssrf: SsrfFilter, ) -> Result<Option<Self>, PluginExit>

Build the per-request chain for route. Ok(None) — with zero allocations — when the route references no plugins (the fast path). Err(response) is the fail-closed 500 a caller returns immediately: a referenced plugin is Crashed/Disabled/not loaded, a native name is missing from the registry, a native factory errors while the chain is built, or per-request WASM instantiation failed or did not cover every WASM plugin.

Source

pub fn needs_request_body(&self) -> bool

Whether the chain has any plugin declaring request_body (buffers the request body when true — see the module docs).

Source

pub fn needs_response_body(&self) -> bool

Whether the chain has any plugin declaring response_body (buffers the response body when true — see the module docs).

Source

pub async fn request_headers_phase( &mut self, method: &Method, path_and_query: &str, headers: &mut HeaderMap, obs: &Observability, rid: &str, route: &str, ) -> Result<PluginTargetRewrite, PluginExit>

Run the request_headers phase: after route resolution, before authn (the documented contract — authn sees plugin-modified headers). path_and_query is the full request target (path including any query string). On Ok the (possibly rewritten) header map is in place and the returned PluginTargetRewrite carries the chain’s validated :path/:method/:authority writes (see the module’s “Header conventions” section) for the caller to apply at the forward build; on Err the caller returns the response immediately. Async because a plugin may dispatch HTTP callouts here (DW-167): the phase pauses, the callouts are performed off-thread, and the chain resumes with the plugin’s post-callout output.

Source

pub async fn request_body_phase<B>( &mut self, req: Request<B>, cap: u64, obs: &Observability, rid: &str, route: &str, ) -> Result<Request<Full<Bytes>>, PluginExit>
where B: Body<Data = Bytes> + Send + 'static, B::Error: Into<Box<dyn Error + Send + Sync>>,

Run the request_body phase: buffer the request body (capped — over-cap answers 500 plugin_body_too_large, fail-closed), let the chain rewrite it, and hand the action a fully-buffered Full<Bytes> body with a rewritten Content-Length. Runs after authz/rate-limit, before the route action (and before request validation, which then sees the post-plugin bytes).

Source

pub async fn response_headers_phase( &mut self, status: StatusCode, headers: &mut HeaderMap, obs: &Observability, rid: &str, route: &str, ) -> Result<(), PluginExit>

Run the response_headers phase: after the response arrives (any action: proxy, mock, respond, redirect alike — plugins are route-level), before masking. :status rides the map for visibility; plugin writes to it are IGNORED — a deliberate asymmetry with the request-side target rewrite: by the time this phase runs the status is bound to the response’s framing (204/304/101 carry no body, and Content-Length already matches the upstream bytes a later phase may rewrite), so a mid-pipeline flip would desynchronize both. A plugin that wants to DECIDE the answer has send_http_response at the request phases. Async for the callout pause/resume path (DW-167), like every phase method.

Source

pub async fn response_body_phase( &mut self, resp: Response<ProxyBody>, cap: u64, obs: &Observability, rid: &str, route: &str, ) -> Result<Response<ProxyBody>, PluginExit>

Run the response_body phase: after masking, before the operator transforms and compression. Bodiless statuses (informational, 101, 204, 304) have nothing to inspect and pass through untouched, exactly like masking; STREAMING bodies (text/event-stream, or a body of unknown length — chunked or otherwise un-framed) and CONTENT-ENCODED bodies are skipped, documented and logged once per response: buffering an endless SSE stream would stall the route, and an encoded body is opaque bytes to the plugin (dwara never decompresses on this path — compression is applied downstream, after this phase). Every other response on a chain with a response_body plugin is buffered up to cap (over-cap answers 500 plugin_body_too_large, fail-closed), the chain may rewrite the bytes, and the response is rebuilt with a Full body and a rewritten Content-Length. When masking already buffered the body (its fail-closed path) this rides the same buffered bytes.

Trait Implementations§

Source§

impl Drop for RequestPlugins

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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
§

impl<T> AnyExt for T
where T: Any + ?Sized,

§

fn downcast_ref<T>(this: &Self) -> Option<&T>
where T: Any,

Attempts to downcast this to T behind reference
§

fn downcast_mut<T>(this: &mut Self) -> Option<&mut T>
where T: Any,

Attempts to downcast this to T behind mutable reference
§

fn downcast_rc<T>(this: Rc<Self>) -> Result<Rc<T>, Rc<Self>>
where T: Any,

Attempts to downcast this to T behind Rc pointer
§

fn downcast_arc<T>(this: Arc<Self>) -> Result<Arc<T>, Arc<Self>>
where T: Any,

Attempts to downcast this to T behind Arc pointer
§

fn downcast_box<T>(this: Box<Self>) -> Result<Box<T>, Box<Self>>
where T: Any,

Attempts to downcast this to T behind Box pointer
§

fn downcast_move<T>(this: Self) -> Option<T>
where T: Any, Self: Sized,

Attempts to downcast owned Self to T, useful only in generic context as a workaround for specialization
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
§

impl<T, X> CoerceTo<T> for X
where T: CoerceFrom<X> + ?Sized,

§

fn coerce_rc_to(self: Rc<X>) -> Rc<T>

§

fn coerce_box_to(self: Box<X>) -> Box<T>

§

fn coerce_ref_to(&self) -> &T

§

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

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<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
Source§

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

Source§

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>,

Source§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,