Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 14 additions & 40 deletions doc/modules/ROOT/pages/2.guide/2m.compression.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,38 @@
= Compression

Burl can advertise the content codings it accepts and transparently decode a
compressed response body, so `gzip`, `deflate`, and `br` responses arrive
already decompressed. Decoding depends on the relevant service being installed
in the system context.
compressed response body, so `gzip`, `deflate`, `br`, and `zstd` responses
arrive already decompressed. Decoding for each coding is compiled into the
library when it is built with the corresponding compression library.

== Installing the Decode Services
== Build Support

Decoding is provided by Boost.Http and must be registered in the system context
once, at startup, before any request. The zlib service handles `gzip` and
`deflate`; the brotli service handles `br`:

[source,cpp]
----
#include <boost/http/zlib.hpp>
#include <boost/http/brotli.hpp>

int main()
{
http::zlib::install_inflate_service(capy::get_system_context());
http::brotli::install_decode_service(capy::get_system_context());

// ... run the client ...
}
----

These are available only when Boost.Http is built with zlib and brotli support.
Guarding the calls with the feature macros keeps the program portable across
builds that lack them:

[source,cpp]
----
#ifdef BOOST_HTTP_HAS_ZLIB
http::zlib::install_inflate_service(capy::get_system_context());
#endif
#ifdef BOOST_HTTP_HAS_BROTLI
http::brotli::install_decode_service(capy::get_system_context());
#endif
----
The build detects zlib, Brotli, and zstd and enables the codings they provide:
zlib handles `gzip` and `deflate`, Brotli handles `br`, and zstd handles
`zstd`. The macros `BOOST_BURL_HAS_ZLIB`, `BOOST_BURL_HAS_BROTLI`, and
`BOOST_BURL_HAS_ZSTD` indicate which codings the library was built with.

== How It Works

With a service installed and the corresponding setting enabled, the client adds
that coding to the `Accept-Encoding` request header and decodes a response
encoded with it.
Every supported coding is enabled by default: the client adds it to the
`Accept-Encoding` request header and decodes a response encoded with it. The
configuration controls each coding individually.

[source,cpp]
----
burl::client::config cfg;
cfg.gzip = true;
cfg.deflate = true;
cfg.brotli = false; // do not advertise or decode br
cfg.zstd = false; // do not advertise or decode zstd

burl::client client(co_await capy::this_coro::executor, tls_ctx, cfg);
----

[NOTE]
====
A coding whose decode service is not installed is disabled regardless of the
setting, since the client cannot honor what it advertises.
A coding whose decoder was not compiled into the library is disabled regardless
of the setting, since the client cannot honor what it advertises.
====

The decoding is transparent: the body you read through
Expand Down
6 changes: 3 additions & 3 deletions include/boost/burl/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ class client
/** Constructor.

Constructs a client with the provided
configuration. Content codings whose decode
service is not installed in the system
context are disabled, regardless of the
configuration. Content codings whose
decoder was not compiled into the library
are disabled, regardless of the
configuration.

@param exec The executor used to perform
Expand Down
15 changes: 15 additions & 0 deletions include/boost/burl/detail/circular_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ struct circular_buffer
bool
full() const noexcept;

bool
wrapped() const noexcept;

std::size_t
size() const noexcept;

Expand All @@ -52,6 +55,18 @@ struct circular_buffer

void
consume(std::size_t n) noexcept;

void
reset(char* p) noexcept;

void
shed(std::size_t n) noexcept;

void
slide(char* p) noexcept;

char*
linearize(char* floor) noexcept;
};

} // namespace detail
Expand Down
15 changes: 11 additions & 4 deletions include/boost/burl/detail/connection_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <boost/burl/test/fwd.hpp>
#include <boost/capy/buffers.hpp>
#include <boost/capy/detail/buffer_array.hpp>
#include <boost/capy/io/any_stream.hpp>
#include <boost/capy/io_task.hpp>

#include <chrono>
Expand Down Expand Up @@ -94,10 +93,18 @@ class pooled_connection
public:
pooled_connection() = default;

capy::any_stream
stream() noexcept
template<capy::MutableBufferSequence MB>
capy::io_task<std::size_t>
read_some(MB buffers)
{
return conn_->read_some(std::move(buffers));
}

template<capy::ConstBufferSequence CB>
capy::io_task<std::size_t>
write_some(CB buffers)
{
return conn_.get();
return conn_->write_some(std::move(buffers));
}

explicit
Expand Down
207 changes: 0 additions & 207 deletions include/boost/burl/detail/parser.hpp

This file was deleted.

Loading
Loading