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
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ jobs:
apt-get-add-architecture: ${{ matrix.x86 && 'i386' || '' }}
apt-get: >-
${{ matrix.install }}
build-essential libssl-dev zlib1g-dev libbrotli-dev
${{ matrix.x86 && 'libssl-dev:i386 zlib1g-dev:i386 libbrotli-dev:i386' || '' }}
build-essential libssl-dev zlib1g-dev libbrotli-dev libzstd-dev
${{ matrix.x86 && 'libssl-dev:i386 zlib1g-dev:i386 libbrotli-dev:i386 libzstd-dev:i386' || '' }}

- name: Clone Boost
uses: alandefreitas/cpp-actions/boost-clone@v1.9.4
Expand All @@ -283,7 +283,7 @@ jobs:
if: ${{ startsWith(matrix.runs-on, 'windows') }}
id: package-install-windows
with:
vcpkg: zlib brotli openssl
vcpkg: zlib brotli zstd openssl
vcpkg-dir: vcpkg-root
vcpkg-triplet: ${{ matrix.x86 && 'x86-windows-static' || 'x64-windows' }}

Expand All @@ -303,6 +303,7 @@ jobs:

echo "using zlib : : <include>\"${home}/vcpkg-root/installed/${triplet}/include\" <search>\"${home}/vcpkg-root/installed/${triplet}/lib\" <dll-path>\"${home}/vcpkg-root/installed/${triplet}/bin\" <name>zlib : <address-model>${addrmdl} ;" | sed 's/\/d\//D:\//g' >> user-config.jam
echo "using brotli : : <include>\"${home}/vcpkg-root/installed/${triplet}/include\" <search>\"${home}/vcpkg-root/installed/${triplet}/lib\" <dll-path>\"${home}/vcpkg-root/installed/${triplet}/bin\" : <address-model>${addrmdl} ;" | sed 's/\/d\//D:\//g' >> user-config.jam
echo "using zstd : : <include>\"${home}/vcpkg-root/installed/${triplet}/include\" <search>\"${home}/vcpkg-root/installed/${triplet}/lib\" <dll-path>\"${home}/vcpkg-root/installed/${triplet}/bin\" : <address-model>${addrmdl} ;" | sed 's/\/d\//D:\//g' >> user-config.jam
echo "using openssl : : <include>\"${home}/vcpkg-root/installed/${triplet}/include\" <search>\"${home}/vcpkg-root/installed/${triplet}/lib\" <dll-path>\"${home}/vcpkg-root/installed/${triplet}/bin\" <ssl-name>libssl <crypto-name>libcrypto : <address-model>${addrmdl} ;" | sed 's/\/d\//D:\//g' >> user-config.jam

cat user-config.jam
Expand Down
27 changes: 0 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,33 +193,6 @@ if (Libpsl_FOUND)
target_compile_definitions(boost_burl PRIVATE BOOST_BURL_HAS_LIBPSL)
endif ()

#-------------------------------------------------
#
# Compression backends (optional)
#
#-------------------------------------------------

# zlib: deflate and gzip content codings
find_package(ZLIB)
if (ZLIB_FOUND)
target_link_libraries(boost_burl PRIVATE ZLIB::ZLIB)
target_compile_definitions(boost_burl PUBLIC BOOST_BURL_HAS_ZLIB)
endif ()

# Brotli: br content coding (decoding only)
find_package(Brotli)
if (Brotli_FOUND)
target_link_libraries(boost_burl PRIVATE Brotli::common Brotli::decoder)
target_compile_definitions(boost_burl PUBLIC BOOST_BURL_HAS_BROTLI)
endif ()

# Zstandard: zstd content coding
find_package(Zstd)
if (Zstd_FOUND)
target_link_libraries(boost_burl PRIVATE Zstd::Zstd)
target_compile_definitions(boost_burl PUBLIC BOOST_BURL_HAS_ZSTD)
endif ()

#-------------------------------------------------
#
# Tests
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ One line to make a request.
- **Automatic redirects** — 301/302/303/307/308 with standards-compliant
method changes, `Referer` handling, and credential stripping on
cross-origin hops.
- **Content encodings** — transparent `gzip`, `deflate`, and `br` decoding
when the corresponding decode service is installed.
- **Content encodings** — transparent `gzip`, `deflate`, `br`, and `zstd`
decoding when the corresponding decode service is installed.
- **Cookies** — RFC 6265bis jar with optional public-suffix validation (libpsl).
- **Authentication** — Basic and Bearer, per client or per request.
- **Proxies** — `http`, `socks5`, with credentials.
Expand Down
9 changes: 0 additions & 9 deletions build/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import ac ;
import config : requires ;

using openssl ;
using zlib ;
using brotli ;
using zstd ;

constant c11-requires :
[ requires
Expand Down Expand Up @@ -41,9 +38,6 @@ lib boost_burl
<library>/boost//capy
<library>/boost//corosio
[ ac.check-library /boost/corosio//boost_corosio_openssl : <library>/boost/corosio//boost_corosio_openssl : ]
[ ac.check-library /zlib//zlib : <library>/zlib//zlib <define>BOOST_BURL_HAS_ZLIB : ]
[ ac.check-library /brotli//brotlidec : <library>/brotli//brotlicommon <library>/brotli//brotlidec <define>BOOST_BURL_HAS_BROTLI : ]
[ ac.check-library /zstd//zstd : <library>/zstd//zstd <define>BOOST_BURL_HAS_ZSTD : ]
<library>/boost//http
<library>/boost//json
<library>/boost//url
Expand All @@ -53,9 +47,6 @@ lib boost_burl
<library>/boost//capy
<library>/boost//corosio
[ ac.check-library /boost/corosio//boost_corosio_openssl : <library>/boost/corosio//boost_corosio_openssl : ]
[ ac.check-library /zlib//zlib : <library>/zlib//zlib <define>BOOST_BURL_HAS_ZLIB : ]
[ ac.check-library /brotli//brotlidec : <library>/brotli//brotlicommon <library>/brotli//brotlidec <define>BOOST_BURL_HAS_BROTLI : ]
[ ac.check-library /zstd//zstd : <library>/zstd//zstd <define>BOOST_BURL_HAS_ZSTD : ]
<library>/boost//http
<library>/boost//json
<library>/boost//url
Expand Down
50 changes: 0 additions & 50 deletions cmake/FindBrotli.cmake

This file was deleted.

33 changes: 0 additions & 33 deletions cmake/FindZstd.cmake

This file was deleted.

44 changes: 32 additions & 12 deletions doc/modules/ROOT/pages/2.guide/2m.compression.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,40 @@

Burl can advertise the content codings it accepts and transparently decode a
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.
arrive already decompressed. Decoding depends on the relevant Boost.Http
service being installed in the system context.

== Build Support
== Installing the Decode Services

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.
Decoding is provided by Boost.Http and must be registered in the system context once at startup, before any clients are constructed.

The decoder services are provided by the `Boost::http_brotli`, `Boost::http_zlib`, and `Boost::http_zstd` libraries. Each library is available only when Boost.Http is built with the corresponding compression library. Link the libraries for the compression formats you use, and guard the installation calls with the feature macros they define. This keeps the program portable across builds that do not include all compression libraries.

[source,cpp]
----
// Install the available decoder services.
[[maybe_unused]] auto& ctx = capy::get_system_context();

#ifdef BOOST_HTTP_HAS_BROTLI
http::brotli::install_decode_service(ctx);
#endif

#ifdef BOOST_HTTP_HAS_ZLIB
http::zlib::install_inflate_service(ctx);
#endif

#ifdef BOOST_HTTP_HAS_ZSTD
http::zstd::install_decompress_service(ctx);
#endif
----

Burl does not link against any compression library directly. Instead, it looks up the corresponding decoder services at run time.

== How It Works

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.
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.

[source,cpp]
----
Expand All @@ -40,8 +59,9 @@ burl::client client(co_await capy::this_coro::executor, tls_ctx, cfg);

[NOTE]
====
A coding whose decoder was not compiled into the library is disabled regardless
of the setting, since the client cannot honor what it advertises.
A coding whose decode service is not installed when the client is constructed
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
9 changes: 5 additions & 4 deletions doc/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ non-throwing alternatives.
timeouts and per-host caps
* *Automatic redirects* — 301/302/303/307/308 with standards-compliant method
changes, `Referer` handling, and credential stripping on cross-origin hops
* *Content decoding* — transparent `gzip`, `deflate`, and `br` when the
corresponding decode service is installed
* *Content decoding* — transparent `gzip`, `deflate`, `br`, and `zstd` when
the corresponding decode service is installed
* *Cookies* — an RFC 6265bis jar with optional public-suffix validation, and
persistence in the Netscape cookie file format
* *Authentication* — Basic and Bearer, set per client or per request
Expand Down Expand Up @@ -90,8 +90,9 @@ Burl is a focused HTTP/1.1 client. It does not provide:

Boost.Burl is built on Boost.Capy, Boost.Corosio, and Boost.Http, and uses
Boost.URL, Boost.JSON, and Boost.System. Content decoding requires Boost.Http
built with zlib (`gzip`, `deflate`) and brotli (`br`). Public-suffix
validation of cookies requires libpsl.
built with zlib (`gzip`, `deflate`), brotli (`br`), and zstd (`zstd`), with
the corresponding decode services installed in the system context.
Public-suffix validation of cookies requires libpsl.

== Code Conventions

Expand Down
7 changes: 6 additions & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
#

add_executable(burl_example_usage usage.cpp)
target_link_libraries(burl_example_usage PRIVATE Boost::burl Boost::hash2)
target_link_libraries(burl_example_usage PRIVATE
Boost::burl
Boost::hash2
$<TARGET_NAME_IF_EXISTS:Boost::http_zlib>
$<TARGET_NAME_IF_EXISTS:Boost::http_brotli>
$<TARGET_NAME_IF_EXISTS:Boost::http_zstd>)

find_package(nlohmann_json QUIET)
if (nlohmann_json_FOUND)
Expand Down
5 changes: 5 additions & 0 deletions example/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# Official repository: https://github.com/cppalliance/burl
#

import ac ;

lib advapi32 ;
lib crypt32 ;
lib gdi32 ;
Expand All @@ -16,6 +18,9 @@ project
: requirements
<library>/boost/burl//boost_burl
<library>/boost/hash2//boost_hash2
[ ac.check-library /boost/http//boost_http_zlib : <library>/boost/http//boost_http_zlib : ]
[ ac.check-library /boost/http//boost_http_brotli : <library>/boost/http//boost_http_brotli : ]
[ ac.check-library /boost/http//boost_http_zstd : <library>/boost/http//boost_http_zstd : ]
<target-os>windows:<library>advapi32
<target-os>windows:<library>crypt32
<target-os>windows:<library>gdi32
Expand Down
15 changes: 15 additions & 0 deletions example/usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <boost/burl.hpp>
#include <boost/capy.hpp>
#include <boost/corosio.hpp>
#include <boost/http/brotli.hpp>
#include <boost/http/zlib.hpp>
#include <boost/http/zstd.hpp>
#include <boost/json.hpp>
#include <boost/hash2/sha2.hpp>

Expand Down Expand Up @@ -567,6 +570,18 @@ main(int argc, char* argv[])
corosio::io_context ioc;
corosio::tls_context tls_ctx;

// Install avialable decoder services.
[[maybe_unused]] auto& ctx = capy::get_system_context();
#ifdef BOOST_HTTP_HAS_BROTLI
http::brotli::install_decode_service(ctx);
#endif
#ifdef BOOST_HTTP_HAS_ZLIB
http::zlib::install_inflate_service(ctx);
#endif
#ifdef BOOST_HTTP_HAS_ZSTD
http::zstd::install_decompress_service(ctx);
#endif

capy::run_async(
ioc.get_executor(),
[] {},
Expand Down
Loading
Loading