Boost.Http.Proto Project Highlights
Oct 25, 2024Here’s a look at some recent projects I’ve been focusing on:
Boost.Http.Proto
Parsing Chunked Bodies
The http_proto::parser
uses a circular buffer internally, which sometimes causes HTTP message bodies to span across two buffers. Previously, this required copying data into a temporary buffer for chunked parsing, ensuring continuous memory access. To address this, I introduced a chained_sequence
abstraction, which lets two buffers appear as a single, contiguous buffer without the need for copying. This approach streamlines the parser implementation and improves efficiency by reducing memory operations. Iterating over chained_sequence
is nearly as fast as iterating over a single range because it requires only a single comparison per iteration.
gzip/deflate Support
One goal for Http.Proto
is to offer optional support for compression algorithms like gzip, deflate, and brotli, keeping dependencies optional. This allows flexibility, as users may not need compression or might lack libraries like Zlib on their platform. To enable this, we introduced an optional Zlib interface within http_proto
, allowing gzip/deflate support in http_proto::parser
without mandatory linking. Now, the parser can read the Content-Encoding
field and apply the necessary decoding if a suitable compression service is available.
Boost.Http.Io
Following updates in Http.Proto
, I refactored the C++20 coroutine client example in Http.Io
. The client now requests with Accept-Encoding: gzip, deflate
and decodes responses accordingly. It also includes basic redirect support and streams the response body piece by piece to standard output, allowing it to handle large file downloads.
Boost.Beast
Alongside routine bug fixes and responses to user-reported issues, here are a few notable changes in the Boost.Beast project:
beast::basic_parser
Enhancement: A newtrailer_fields
state was added for parsing trailer fields in chunked HTTP message bodies. This state respects user-definedheader_limit
settings and provides appropriate error messages when limits are exceeded.- Error Handling in
basic_fields
:basic_fields
interfaces now include an overload that accepts asystem::error_code
instead of throwing exceptions. This enables parsers to report insertion errors directly to the caller. skip_
Variable Removal: The parser previously used a state variableskip_
to track parsed characters inCRLF
processing within chunk headers. Benchmarks showed that removingskip_
improves performance, as the parser can findCRLF
directly within the buffer. This change has also simplified the parser’s implementation.- Forward-Declared Headers for
beast::http
: New forward-declared headers are now available for all types in thebeast::http
namespace, enabling users to separate implementation and usage sites more effectively by including only the necessary*_fwd
headers.
All Posts by This Author
- 10/25/2024 Boost.Http.Proto Project Highlights
- 07/10/2024 Mohammad's Q2 2024 Update
- 04/22/2024 Mohammad's Q1 2024 Update
- 01/10/2024 Mohammad's Q4 2023 Update
- 10/27/2023 Mohammad's Q3 2023 Update
- View All Posts...