HttpResponseConsumer

Struct HttpResponseConsumer 

Source
pub struct HttpResponseConsumer {
    pub config: ConsumerConfig<HttpResponse>,
    pub http_config: HttpResponseConsumerConfig,
    pub responses: Vec<HttpResponse>,
    pub finished: bool,
}
Expand description

A consumer that converts stream items into HTTP responses.

This consumer accepts HttpResponse items from a pipeline and converts them into Axum Response<Body> that can be sent back to clients. It supports both single-item and multi-item responses, as well as streaming responses.

§Example

use streamweave::http_server::{HttpResponseConsumer, HttpResponseConsumerConfig};
use streamweave::http_server::HttpResponse;
use axum::http::StatusCode;

async fn handle_response(mut consumer: HttpResponseConsumer) {
    let response = consumer.get_response().await;
    // Send response to client
}

Fields§

§config: ConsumerConfig<HttpResponse>

Consumer configuration.

§http_config: HttpResponseConsumerConfig

HTTP response-specific configuration.

§responses: Vec<HttpResponse>

Collected responses.

§finished: bool

Whether the consumer has finished consuming.

Implementations§

Source§

impl HttpResponseConsumer

Source

pub fn new() -> Self

Creates a new HTTP response consumer with default configuration.

§Example
use streamweave::http_server::HttpResponseConsumer;

let consumer = HttpResponseConsumer::new();
Source

pub fn with_config(http_config: HttpResponseConsumerConfig) -> Self

Creates a new HTTP response consumer with custom configuration.

§Example
use streamweave::http_server::{HttpResponseConsumer, HttpResponseConsumerConfig};

let consumer = HttpResponseConsumer::with_config(
    HttpResponseConsumerConfig::default()
        .with_stream_response(true)
        .with_merge_responses(false),
);
Source

pub fn with_error_strategy(self, strategy: ErrorStrategy<HttpResponse>) -> Self

Sets the error strategy for the consumer.

Source

pub fn with_name(self, name: String) -> Self

Sets the name for the consumer.

Source

pub async fn get_response(&mut self) -> Response<Body>

Gets the collected response as an Axum Response.

This should be called after consume has completed. For single-item responses, it returns the first response. For multi-item responses, it merges them according to the configuration.

§Example
use streamweave::http_server::HttpResponseConsumer;

let mut consumer = HttpResponseConsumer::new();
// ... consume stream ...
let axum_response = consumer.get_response().await;
Source

pub async fn create_streaming_response( &self, stream: impl Stream<Item = HttpResponse> + Send + 'static, ) -> Response<Body>

Creates a streaming response from a stream of HttpResponse items.

This method converts a stream of HttpResponse items into a streaming Axum response with chunked transfer encoding. The first response’s status and headers are used, and subsequent responses’ bodies are streamed as chunks.

§Example
use streamweave::http_server::{HttpResponseConsumer, HttpResponse};
use streamweave::consumer::Consumer;
use futures::StreamExt;
use axum::http::StatusCode;

async fn stream_responses(mut stream: impl futures::Stream<Item = HttpResponse> + Send) {
    let consumer = HttpResponseConsumer::new();
    let response = consumer.create_streaming_response(stream).await;
    // Send response to client
}
Source

pub fn http_config(&self) -> &HttpResponseConsumerConfig

Returns the HTTP response configuration.

Source

pub fn responses(&self) -> &[HttpResponse]

Returns the collected responses.

Trait Implementations§

Source§

impl Clone for HttpResponseConsumer

Available on non-WebAssembly and crate feature http-server only.
Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Consumer for HttpResponseConsumer

Source§

fn consume<'life0, 'async_trait>( &'life0 mut self, stream: Self::InputStream, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Consumes a stream of HTTP response items.

This collects all HttpResponse items from the stream and stores them for later conversion to an Axum response via get_response().

§Error Handling
  • Errors are handled according to the error strategy.
  • Invalid responses are logged but may be skipped based on strategy.
Source§

fn set_config_impl(&mut self, config: ConsumerConfig<HttpResponse>)

Internal implementation for setting configuration.
Source§

fn get_config_impl(&self) -> &ConsumerConfig<HttpResponse>

Internal implementation for getting configuration.
Source§

fn get_config_mut_impl(&mut self) -> &mut ConsumerConfig<HttpResponse>

Internal implementation for getting mutable configuration.
Source§

fn with_config(&self, config: ConsumerConfig<Self::Input>) -> Self
where Self: Sized + Clone,

Creates a new consumer instance with the given configuration. Read more
Source§

fn set_config(&mut self, config: ConsumerConfig<Self::Input>)

Sets the configuration for this consumer. Read more
Source§

fn config(&self) -> &ConsumerConfig<Self::Input>

Returns a reference to the consumer’s configuration.
Source§

fn config_mut(&mut self) -> &mut ConsumerConfig<Self::Input>

Returns a mutable reference to the consumer’s configuration.
Source§

fn with_name(self, name: String) -> Self
where Self: Sized,

Sets the name for this consumer. Read more
Source§

fn handle_error(&self, error: &StreamError<Self::Input>) -> ErrorAction

Handles an error according to the consumer’s error strategy. Read more
Source§

fn component_info(&self) -> ComponentInfo

Returns information about this consumer component.
Source§

fn create_error_context( &self, item: Option<Self::Input>, ) -> ErrorContext<Self::Input>

Creates an error context for the given item. Read more
Source§

impl Debug for HttpResponseConsumer

Source§

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

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

impl Default for HttpResponseConsumer

Available on non-WebAssembly and crate feature http-server only.
Source§

fn default() -> Self

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

impl Input for HttpResponseConsumer

Source§

type Input = HttpResponse

The type of items produced by this input stream.
Source§

type InputStream = Pin<Box<dyn Stream<Item = <HttpResponseConsumer as Input>::Input> + Send>>

The input stream type that yields items of type Self::Input.

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
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

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

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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