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: HttpResponseConsumerConfigHTTP response-specific configuration.
responses: Vec<HttpResponse>Collected responses.
finished: boolWhether the consumer has finished consuming.
Implementations§
Source§impl HttpResponseConsumer
impl HttpResponseConsumer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new HTTP response consumer with default configuration.
§Example
use streamweave::http_server::HttpResponseConsumer;
let consumer = HttpResponseConsumer::new();Sourcepub fn with_config(http_config: HttpResponseConsumerConfig) -> Self
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),
);Sourcepub fn with_error_strategy(self, strategy: ErrorStrategy<HttpResponse>) -> Self
pub fn with_error_strategy(self, strategy: ErrorStrategy<HttpResponse>) -> Self
Sets the error strategy for the consumer.
Sourcepub async fn get_response(&mut self) -> Response<Body>
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;Sourcepub async fn create_streaming_response(
&self,
stream: impl Stream<Item = HttpResponse> + Send + 'static,
) -> Response<Body>
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
}Sourcepub fn http_config(&self) -> &HttpResponseConsumerConfig
pub fn http_config(&self) -> &HttpResponseConsumerConfig
Returns the HTTP response configuration.
Sourcepub fn responses(&self) -> &[HttpResponse]
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.
impl Clone for HttpResponseConsumer
http-server only.Source§impl Consumer for HttpResponseConsumer
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,
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>)
fn set_config_impl(&mut self, config: ConsumerConfig<HttpResponse>)
Source§fn get_config_impl(&self) -> &ConsumerConfig<HttpResponse>
fn get_config_impl(&self) -> &ConsumerConfig<HttpResponse>
Source§fn get_config_mut_impl(&mut self) -> &mut ConsumerConfig<HttpResponse>
fn get_config_mut_impl(&mut self) -> &mut ConsumerConfig<HttpResponse>
Source§fn with_config(&self, config: ConsumerConfig<Self::Input>) -> Self
fn with_config(&self, config: ConsumerConfig<Self::Input>) -> Self
Source§fn set_config(&mut self, config: ConsumerConfig<Self::Input>)
fn set_config(&mut self, config: ConsumerConfig<Self::Input>)
Source§fn config(&self) -> &ConsumerConfig<Self::Input>
fn config(&self) -> &ConsumerConfig<Self::Input>
Source§fn config_mut(&mut self) -> &mut ConsumerConfig<Self::Input>
fn config_mut(&mut self) -> &mut ConsumerConfig<Self::Input>
Source§fn with_name(self, name: String) -> Selfwhere
Self: Sized,
fn with_name(self, name: String) -> Selfwhere
Self: Sized,
Source§fn handle_error(&self, error: &StreamError<Self::Input>) -> ErrorAction
fn handle_error(&self, error: &StreamError<Self::Input>) -> ErrorAction
Source§fn component_info(&self) -> ComponentInfo
fn component_info(&self) -> ComponentInfo
Source§fn create_error_context(
&self,
item: Option<Self::Input>,
) -> ErrorContext<Self::Input>
fn create_error_context( &self, item: Option<Self::Input>, ) -> ErrorContext<Self::Input>
Source§impl Debug for HttpResponseConsumer
impl Debug for HttpResponseConsumer
Source§impl Default for HttpResponseConsumer
Available on non-WebAssembly and crate feature http-server only.
impl Default for HttpResponseConsumer
http-server only.Source§impl Input for HttpResponseConsumer
impl Input for HttpResponseConsumer
Source§type Input = HttpResponse
type Input = HttpResponse
Source§type InputStream = Pin<Box<dyn Stream<Item = <HttpResponseConsumer as Input>::Input> + Send>>
type InputStream = Pin<Box<dyn Stream<Item = <HttpResponseConsumer as Input>::Input> + Send>>
Self::Input.