pub struct Decoder<'a> { /* private fields */ }Expand description
Decodes headers encoded using HPACK.
For now, incremental decoding is not supported, i.e. it is necessary to pass in the entire encoded representation of all headers to the decoder, rather than processing it piece-by-piece.
Implementations§
Source§impl<'a> Decoder<'a>
Represents a decoder of HPACK encoded headers. Maintains the state
necessary to correctly decode subsequent HPACK blocks.
impl<'a> Decoder<'a>
Represents a decoder of HPACK encoded headers. Maintains the state necessary to correctly decode subsequent HPACK blocks.
Sourcepub fn set_max_table_size(&mut self, new_max_size: usize)
pub fn set_max_table_size(&mut self, new_max_size: usize)
Sets a new maximum dynamic table size for the decoder.
If max_allowed_table_size is set, new_max_size must be <= to it.
Sourcepub fn set_max_allowed_table_size(&mut self, max_allowed_size: usize)
pub fn set_max_allowed_table_size(&mut self, max_allowed_size: usize)
Sets max allowed table size: any “dynamic table size updates” that try to bring the table size over that value will error out with DecoderError::InvalidMaxDynamicSize
Sourcepub fn decode_with_cb(
&mut self,
buf: &[u8],
cb: impl FnMut(Cow<'_, [u8]>, Cow<'_, [u8]>),
) -> Result<(), DecoderError>
pub fn decode_with_cb( &mut self, buf: &[u8], cb: impl FnMut(Cow<'_, [u8]>, Cow<'_, [u8]>), ) -> Result<(), DecoderError>
Decodes the headers found in the given buffer buf. Invokes the
callback cb for each decoded header in turn, by providing it the
header name and value as Cow byte array slices.
The callback is free to decide how to handle the emitted header, however
the Cow cannot outlive the closure body without assuming ownership
or otherwise copying the contents.
This is due to the fact that the header might be found (fully or partially) in the header table of the decoder, in which case the callback will have received a borrow of its contents. However, when one of the following headers is decoded, it is possible that the header table might have to be modified; so the borrow is only valid until the next header decoding begins, meaning until the end of the callback’s body.
If an error is encountered during the decoding of any header, decoding
halts and the appropriate error is returned as the Err variant of
the Result.
Sourcepub fn decode(&mut self, buf: &[u8]) -> DecoderResult
pub fn decode(&mut self, buf: &[u8]) -> DecoderResult
Decode the header block found in the given buffer.
The decoded representation is returned as a sequence of headers, where
both the name and value of each header is represented by an owned
byte sequence (i.e. Vec<u8>).
The buffer should represent the entire block that should be decoded. For example, in HTTP/2, all continuation frames need to be concatenated to a single buffer before passing them to the decoder.