Skip to main content

ContentDecoder

Struct ContentDecoder 

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

Incremental removal of one HTTP content coding.

deflate is the zlib wrapper from RFC 9110, not raw DEFLATE. gzip and x-gzip use the gzip wrapper. Both the encoded input and the decoded output are capped at max_output.

Implementations§

Source§

impl ContentDecoder

Source

pub fn new(coding: Option<&str>, max_output: usize) -> Result<Self, ModelError>

Start a decoder for one coding.

An omitted coding and identity copy the input. Stacked codings and unknown codings are rejected.

§Errors

Returns an error when the coding is not a single supported value.

Source

pub fn push(&mut self, chunk: &[u8]) -> Result<(), ModelError>

Absorb one chunk of the encoded body.

§Errors

Returns an error when the encoded input or decoded output would exceed the cap, or the coding stream is invalid.

Source

pub fn take_output(&mut self) -> Vec<u8> ⓘ

Hand out the decoded bytes produced so far and forget them.

Use this after each ContentDecoder::push to process a large body incrementally. Bytes taken here still count toward the max_output cap, so the cap applies to the whole body. Only complete decoding is meaningful: the stream is validated by ContentDecoder::finish, and until it returns Ok the bytes taken so far must not be treated as a valid artifact.

Experimental.

Source

pub fn finish(self) -> Result<Vec<u8>, ModelError>

Finish the coding stream and return the decoded bytes.

Bytes already handed out by ContentDecoder::take_output are not returned again.

§Errors

Returns an error when the stream is truncated or the output cap is exceeded.

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> 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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.