Enum StreamingBody

Source
pub enum StreamingBody<B> {
    Buffered {
        data: Option<Bytes>,
    },
    Streaming {
        inner: B,
    },
}
Expand description

A body type that can represent either buffered data from cache or streaming body from upstream.

This enum allows the HTTP cache middleware to efficiently handle:

  • Cached responses (buffered data)
  • Cache misses (streaming from upstream)

§Variants

  • Buffered: Contains cached response data that can be sent immediately
  • Streaming: Wraps an upstream body for streaming responses

§Example

use http_cache::StreamingBody;
use bytes::Bytes;
use http_body_util::Full;

// Cached response - sent immediately from memory
let cached: StreamingBody<Full<Bytes>> = StreamingBody::buffered(Bytes::from("Hello from cache!"));

// Streaming response - passed through from upstream
let upstream_body = MyBody;
let streaming = StreamingBody::streaming(upstream_body);

Variants§

§

Buffered

Fields

§

Streaming

Fields

§inner: B

Implementations§

Source§

impl<B> StreamingBody<B>

Source

pub fn buffered(data: Bytes) -> Self

Create a new buffered body from bytes

Source

pub fn streaming(body: B) -> Self

Create a new streaming body from an upstream body

Trait Implementations§

Source§

impl<B> Body for StreamingBody<B>
where B: Body + Unpin, B::Error: Into<StreamingError>, B::Data: Into<Bytes>,

Source§

type Data = Bytes

Values yielded by the Body.
Source§

type Error = StreamingError

The error type this Body might generate.
Source§

fn poll_frame( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>>

Attempt to pull out the next data buffer of this stream.
Source§

fn is_end_stream(&self) -> bool

Returns true when the end of stream has been reached. Read more
Source§

fn size_hint(&self) -> SizeHint

Returns the bounds on the remaining length of the stream. Read more
Source§

impl<B> From<Bytes> for StreamingBody<B>

Source§

fn from(bytes: Bytes) -> Self

Converts to this type from the input type.
Source§

impl<'__pin, B> Unpin for StreamingBody<B>
where PinnedFieldsOf<__Origin<'__pin, B>>: Unpin,

Auto Trait Implementations§

§

impl<B> !Freeze for StreamingBody<B>

§

impl<B> RefUnwindSafe for StreamingBody<B>
where B: RefUnwindSafe,

§

impl<B> Send for StreamingBody<B>
where B: Send,

§

impl<B> Sync for StreamingBody<B>
where B: Sync,

§

impl<B> UnwindSafe for StreamingBody<B>
where B: 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.

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<T> ErasedDestructor for T
where T: 'static,