Crate uhttp_chunked_bytes [] [src]

This crate provides a zero-allocation iterator for the payload bytes in an HTTP chunked-encoded body. It wraps a given iterator over raw HTTP body bytes, decodes the chunked transfer protocol, and yields the data bytes from each chunk. The result can be fed, for example, into a byte-based parser such as serde_json::from_iter.

This implementation supports chunk lengths up to that which can be stored by usize on the target platform. Chunk extension parameters are discarded, and trailing headers aren't processed, although they can be retrieved from the wrapped source iterator at the end of chunked payload iteration.


use uhttp_chunked_bytes::ChunkedBytes;

// Create a sample json body `{"key": 42}`, split over two chunks.
let body = b"4\r\n{\"ke\r\n7\r\ny\": 42}\r\n0\r\n\r\n";
let mut stream = body.iter().map(|&b| Ok(b));

let mut bytes = ChunkedBytes::new(&mut stream);
assert_eq!(, b'{');
assert_eq!(, b'"');
assert_eq!(, b'k');
assert_eq!(, b'e');
assert_eq!(, b'y');
assert_eq!(, b'"');
assert_eq!(, b':');
assert_eq!(, b' ');
assert_eq!(, b'4');
assert_eq!(, b'2');
assert_eq!(, b'}');



Iterator over payload bytes in a chunked-encoded stream.