Skip to content

Commit 6ff59bb

Browse files
committed
Move zlib and brotli compression from capy to http
Add zlib and brotli compression services from capy. These services provide HTTP content encoding support (gzip, deflate, br) and are better placed in the http library where they are actually used. - Add all zlib/brotli headers, sources, and tests - Change namespace from boost::capy to boost::http - Add compression documentation with cross-references - Update build files (CMake, B2, CI) - Update parser/serializer to use new namespace
1 parent 5ef14b2 commit 6ff59bb

63 files changed

Lines changed: 4095 additions & 71 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ jobs:
290290
apt-get: >-
291291
${{ matrix.install }}
292292
build-essential
293-
${{ matrix.x86 && '' || '' }}
293+
zlib1g-dev libbrotli-dev
294+
${{ matrix.x86 && 'zlib1g-dev:i386 libbrotli-dev:i386' || '' }}
294295
295296
- name: Clone Capy
296297
uses: actions/checkout@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/.clangd
44
/build/*
55
!/build/Jamfile
6+
!/build/brotli.jam
67
/out/
78
/CMakeUserPresets.json
89
/tmpclaude-*-cwd

CMakeLists.txt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ foreach (BOOST_HTTP_DEPENDENCY ${BOOST_HTTP_DEPENDENCIES})
7474
endif ()
7575
endforeach ()
7676
# Conditional dependencies
77-
if (NOT BOOST_URL_MRDOCS_BUILD)
77+
if (NOT BOOST_HTTP_MRDOCS_BUILD)
7878
if (BOOST_HTTP_BUILD_TESTS)
7979
set(BOOST_HTTP_UNIT_TEST_LIBRARIES asio filesystem)
8080
endif ()
@@ -180,6 +180,39 @@ elseif (APPLE)
180180
target_link_libraries(boost_http PRIVATE "-framework Security")
181181
endif ()
182182

183+
# Zlib
184+
find_package(ZLIB)
185+
if (ZLIB_FOUND)
186+
file(GLOB_RECURSE BOOST_HTTP_ZLIB_HEADERS CONFIGURE_DEPENDS include/boost/http/zlib/*.hpp)
187+
file(GLOB_RECURSE BOOST_HTTP_ZLIB_SOURCES CONFIGURE_DEPENDS src_zlib/*.cpp src_zlib/*.hpp)
188+
source_group("" FILES "include/boost/http/zlib.hpp")
189+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost/http/zlib PREFIX "include" FILES ${BOOST_HTTP_ZLIB_HEADERS})
190+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src_zlib PREFIX "src" FILES ${BOOST_HTTP_ZLIB_SOURCES})
191+
add_library(boost_http_zlib include/boost/http/zlib.hpp build/Jamfile ${BOOST_HTTP_ZLIB_HEADERS} ${BOOST_HTTP_ZLIB_SOURCES})
192+
add_library(Boost::http_zlib ALIAS boost_http_zlib)
193+
target_link_libraries(boost_http_zlib PUBLIC boost_http)
194+
target_link_libraries(boost_http_zlib PRIVATE ZLIB::ZLIB)
195+
target_compile_definitions(boost_http_zlib PUBLIC BOOST_HTTP_HAS_ZLIB)
196+
target_compile_definitions(boost_http_zlib PRIVATE BOOST_HTTP_SOURCE)
197+
endif ()
198+
199+
# Brotli
200+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
201+
find_package(Brotli)
202+
if (Brotli_FOUND)
203+
file(GLOB_RECURSE BOOST_HTTP_BROTLI_HEADERS CONFIGURE_DEPENDS include/boost/http/brotli/*.hpp)
204+
file(GLOB_RECURSE BOOST_HTTP_BROTLI_SOURCES CONFIGURE_DEPENDS src_brotli/*.cpp src_brotli/*.hpp)
205+
source_group("" FILES "include/boost/http/brotli.hpp")
206+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost/http/brotli PREFIX "include" FILES ${BOOST_HTTP_BROTLI_HEADERS})
207+
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src_brotli PREFIX "src" FILES ${BOOST_HTTP_BROTLI_SOURCES})
208+
add_library(boost_http_brotli include/boost/http/brotli.hpp build/Jamfile ${BOOST_HTTP_BROTLI_HEADERS} ${BOOST_HTTP_BROTLI_SOURCES})
209+
add_library(Boost::http_brotli ALIAS boost_http_brotli)
210+
target_link_libraries(boost_http_brotli PUBLIC boost_http)
211+
target_link_libraries(boost_http_brotli PRIVATE Brotli::common Brotli::decoder Brotli::encoder)
212+
target_compile_definitions(boost_http_brotli PUBLIC BOOST_HTTP_HAS_BROTLI)
213+
target_compile_definitions(boost_http_brotli PRIVATE BOOST_HTTP_SOURCE)
214+
endif ()
215+
183216
#-------------------------------------------------
184217
#
185218
# Tests

build/Jamfile

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Official repository: https://github.com/vinniefalco/http
88
#
99

10+
import ac ;
1011
import ../../config/checks/config : requires ;
1112

1213
constant c11-requires :
@@ -59,4 +60,36 @@ lib boost_http
5960
<target-os>darwin:<linkflags>"-framework Security"
6061
;
6162

62-
boost-install boost_http ;
63+
# Zlib
64+
using zlib ;
65+
66+
alias http_zlib_sources : [ glob-tree-ex src_zlib : *.cpp ] ;
67+
68+
lib boost_http_zlib
69+
: http_zlib_sources
70+
: requirements
71+
<library>/boost/http//boost_http
72+
[ ac.check-library /zlib//zlib : <library>/zlib//zlib : <build>no ]
73+
: usage-requirements
74+
<library>/boost/http//boost_http
75+
<define>BOOST_HTTP_HAS_ZLIB
76+
;
77+
78+
# Brotli
79+
using brotli ;
80+
81+
alias http_brotli_sources : [ glob-tree-ex src_brotli : *.cpp ] ;
82+
83+
lib boost_http_brotli
84+
: http_brotli_sources
85+
: requirements
86+
<library>/boost/http//boost_http
87+
[ ac.check-library /brotli//brotlicommon : <library>/brotli//brotlicommon : <build>no ]
88+
[ ac.check-library /brotli//brotlidec : <library>/brotli//brotlidec : <build>no ]
89+
[ ac.check-library /brotli//brotlienc : <library>/brotli//brotlienc : <build>no ]
90+
: usage-requirements
91+
<library>/boost/http//boost_http
92+
<define>BOOST_HTTP_HAS_BROTLI
93+
;
94+
95+
boost-install boost_http boost_http_zlib boost_http_brotli ;

build/brotli.jam

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Copyright (c) 2025 Mohammad Nejati
2+
#
3+
# Use, modification and distribution is subject to the Boost Software
4+
# License Version 1.0. (See accompanying file LICENSE.txt or
5+
# https://www.bfgroup.xyz/b2/LICENSE.txt)
6+
7+
# Supports the brotli library
8+
#
9+
# After 'using brotli', the following targets are available:
10+
#
11+
# /brotli//brotlicommon -- The brotli common library
12+
# /brotli//brotlidec -- The brotli decoder library
13+
# /brotli//brotlienc -- The brotli encoder library
14+
15+
import project ;
16+
import ac ;
17+
import errors ;
18+
import feature ;
19+
import "class" : new ;
20+
import targets ;
21+
import path ;
22+
import modules ;
23+
import indirect ;
24+
import property ;
25+
import property-set ;
26+
import args ;
27+
28+
header = brotli/decode.h ;
29+
brotlicommon_names = brotlicommon libbrotlicommon ;
30+
brotlidec_names = brotlidec libbrotlidec ;
31+
brotlienc_names = brotlienc libbrotlienc ;
32+
33+
library-id = 0 ;
34+
35+
.debug = [ args.get-arg debug-configuration ] ;
36+
37+
# Initializes the brotli library.
38+
#
39+
# Options for configuring brotli::
40+
#
41+
# <search>
42+
# The directory containing the brotli binaries.
43+
# <brotlicommon-name>
44+
# Overrides the default name of brotlicommon library.
45+
# <brotlidec-name>
46+
# Overrides the default name of brotlidec library.
47+
# <brotlienc-name>
48+
# Overrides the default name of brotlienc library.
49+
# <include>
50+
# The directory containing the brotli headers.
51+
# <dll-path>
52+
# Extra directories to add to library search paths of consumers during
53+
# runtime (multiple instances are allowed).
54+
#
55+
# If none of these options is specified, then the environmental
56+
# variables BROTLI_LIBRARY_PATH, BROTLI_NAME, and BROTLI_INCLUDE will
57+
# be used instead.
58+
#
59+
# Examples::
60+
#
61+
# # Find brotli in the default system location
62+
# using brotli ;
63+
# # Find brotli in /usr/local
64+
# using brotli : 1.1.0
65+
# : <include>/usr/local/include <search>/usr/local/lib ;
66+
#
67+
rule init (
68+
version ?
69+
# (currently ignored)
70+
71+
: options *
72+
# A list of the options to use
73+
74+
: requirements *
75+
# The requirements for the target
76+
77+
: is-default ?
78+
)
79+
{
80+
local caller = [ project.current ] ;
81+
82+
if ! $(.initialized)
83+
{
84+
.initialized = true ;
85+
86+
project.initialize $(__name__) ;
87+
.project = [ project.current ] ;
88+
project brotli ;
89+
}
90+
91+
local library-path = [ feature.get-values <search> : $(options) ] ;
92+
local include-path = [ feature.get-values <include> : $(options) ] ;
93+
local brotlicommon-name = [ feature.get-values <brotlicommon-name> : $(options) ] ;
94+
local brotlidec-name = [ feature.get-values <brotlidec-name> : $(options) ] ;
95+
local brotlienc-name = [ feature.get-values <brotlienc-name> : $(options) ] ;
96+
local dll-paths = [ property.select <dll-path> : $(options) ] ;
97+
98+
if ! $(options)
99+
{
100+
is-default = true ;
101+
}
102+
103+
condition = [ property-set.create $(requirements) ] ;
104+
condition = [ property-set.create [ $(condition).base ] ] ;
105+
106+
if $(.configured.$(condition))
107+
{
108+
if $(is-default)
109+
{
110+
if $(.debug)
111+
{
112+
ECHO "notice: [brotli] brotli is already configured" ;
113+
}
114+
}
115+
else
116+
{
117+
errors.user-error "brotli is already configured" ;
118+
}
119+
return ;
120+
}
121+
else
122+
{
123+
if $(.debug)
124+
{
125+
ECHO "notice: [brotli] Using pre-installed library" ;
126+
if $(condition)
127+
{
128+
ECHO "notice: [brotli] Condition" [ $(condition).raw ] ;
129+
}
130+
}
131+
132+
local brotlicommon = [ new ac-library brotlicommon : $(.project) : $(condition) :
133+
$(include-path) : $(library-path) : $(brotlicommon-name) ] ;
134+
$(brotlicommon).set-header $(header) ;
135+
$(brotlicommon).set-default-names $(brotlicommon_names) ;
136+
$(brotlicommon).add-usage-requirements $(dll-paths) ;
137+
138+
local brotlidec = [ new ac-library brotlidec : $(.project) : $(condition) :
139+
$(include-path) : $(library-path) : $(brotlidec-name) ] ;
140+
$(brotlidec).set-header $(header) ;
141+
$(brotlidec).set-default-names $(brotlidec_names) ;
142+
$(brotlidec).add-usage-requirements $(dll-paths) ;
143+
144+
local brotlienc = [ new ac-library brotlienc : $(.project) : $(condition) :
145+
$(include-path) : $(library-path) : $(brotlienc-name) ] ;
146+
$(brotlienc).set-header $(header) ;
147+
$(brotlienc).set-default-names $(brotlienc_names) ;
148+
$(brotlienc).add-usage-requirements $(dll-paths) ;
149+
150+
targets.main-target-alternative $(brotlicommon) ;
151+
targets.main-target-alternative $(brotlidec) ;
152+
targets.main-target-alternative $(brotlienc) ;
153+
}
154+
.configured.$(condition) = true ;
155+
}

cmake/FindBrotli.cmake

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright (c) 2025 Mohammad Nejati
3+
#
4+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
#
7+
# Official repository: https://github.com/cppalliance/http
8+
#
9+
10+
# Provides imported targets:
11+
# Brotli::common
12+
# Brotli::decoder
13+
# Brotli::encoder
14+
15+
find_path(Brotli_INCLUDE_DIR "brotli/decode.h")
16+
find_library(Brotli_COMMON_LIBRARY NAMES "brotlicommon")
17+
find_library(Brotli_DEC_LIBRARY NAMES "brotlidec")
18+
find_library(Brotli_ENC_LIBRARY NAMES "brotlienc")
19+
20+
include(FindPackageHandleStandardArgs)
21+
find_package_handle_standard_args(Brotli
22+
REQUIRED_VARS
23+
Brotli_INCLUDE_DIR
24+
Brotli_COMMON_LIBRARY
25+
Brotli_DEC_LIBRARY
26+
Brotli_ENC_LIBRARY
27+
)
28+
29+
if(Brotli_FOUND)
30+
add_library(Brotli::common UNKNOWN IMPORTED)
31+
set_target_properties(Brotli::common PROPERTIES
32+
IMPORTED_LOCATION ${Brotli_COMMON_LIBRARY}
33+
INTERFACE_INCLUDE_DIRECTORIES ${Brotli_INCLUDE_DIR})
34+
35+
add_library(Brotli::decoder UNKNOWN IMPORTED)
36+
set_target_properties(Brotli::decoder PROPERTIES
37+
IMPORTED_LOCATION ${Brotli_DEC_LIBRARY}
38+
INTERFACE_INCLUDE_DIRECTORIES ${Brotli_INCLUDE_DIR})
39+
40+
add_library(Brotli::encoder UNKNOWN IMPORTED)
41+
set_target_properties(Brotli::encoder PROPERTIES
42+
IMPORTED_LOCATION ${Brotli_ENC_LIBRARY}
43+
INTERFACE_INCLUDE_DIRECTORIES ${Brotli_INCLUDE_DIR})
44+
endif()
45+
46+
mark_as_advanced(
47+
Brotli_INCLUDE_DIR
48+
Brotli_COMMON_LIBRARY
49+
Brotli_DEC_LIBRARY
50+
Brotli_ENC_LIBRARY)

doc/modules/ROOT/nav.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
// ** xref:server/params.adoc[Route Parameters]
1616
// ** xref:server/advanced.adoc[Advanced Topics]
1717
// ** xref:server/cors.adoc[CORS]
18+
* Compression
19+
** xref:compression/zlib.adoc[ZLib]
20+
** xref:compression/brotli.adoc[Brotli]
1821
* Design Requirements
1922
** xref:design_requirements/serializer.adoc[Serializer]
2023
** xref:design_requirements/parser.adoc[Parser]

0 commit comments

Comments
 (0)