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
impl ContentDecoder
Sourcepub fn new(coding: Option<&str>, max_output: usize) -> Result<Self, ModelError>
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.
Sourcepub fn push(&mut self, chunk: &[u8]) -> Result<(), ModelError>
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.
Sourcepub fn take_output(&mut self) -> Vec<u8> ⓘ
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.
Sourcepub fn finish(self) -> Result<Vec<u8>, ModelError>
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.