pub trait Interceptor<T = ()>: Send + Sync {
// Provided methods
fn before_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut BeforeRequestContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn after_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 AfterResponseContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn on_stream_chunk<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 StreamChunkContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn on_stream_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 StreamEndContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn on_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 ErrorContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
}Expand description
Trait for implementing interceptors.
Interceptors can hook into various stages of the request/response lifecycle. All methods have default no-op implementations, so you only need to implement the hooks you’re interested in.
The generic type parameter T defines the state type that will be passed
through the request lifecycle. Use () (the default) for simple interceptors
that don’t need to maintain state across hooks.
Provided Methods§
Sourcefn before_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut BeforeRequestContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn before_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut BeforeRequestContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called before a request is sent.
This method can modify the state that will be passed through the request lifecycle.
Sourcefn after_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 AfterResponseContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn after_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 AfterResponseContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called after a successful non-streaming response is received.
Sourcefn on_stream_chunk<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 StreamChunkContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_stream_chunk<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 StreamChunkContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called for each chunk in a streaming response.
Sourcefn on_stream_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 StreamEndContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_stream_end<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 StreamEndContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when a streaming response completes successfully.
Sourcefn on_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 ErrorContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_error<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 ErrorContext<'life2, T>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called when an error occurs at any stage.
Note: This method doesn’t return a Result as it’s called during error handling and shouldn’t fail.