mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-06 15:20:19 +07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e699bd0730 | ||
|
|
961a9379d5 | ||
|
|
ec87b04aff | ||
|
|
aabf752a51 | ||
|
|
afb0674ccb | ||
|
|
ee625232a4 | ||
|
|
52d8dd41f1 | ||
|
|
be07d2d7a9 | ||
|
|
0f1b62c2b3 | ||
|
|
c30906a541 | ||
|
|
3533503323 | ||
|
|
82acdca638 | ||
|
|
a1e56a567b | ||
|
|
0c17d172a2 | ||
|
|
5d8e7c761f | ||
|
|
17fc522b75 | ||
|
|
f1daa5b88b | ||
|
|
fe9a1949a6 | ||
|
|
50cba6db9f | ||
|
|
18592e7f98 | ||
|
|
bd9612b81e | ||
|
|
7ab5fb65b2 | ||
|
|
8df5fedc35 | ||
|
|
4a61f68fa4 | ||
|
|
067890133c | ||
|
|
d3076f5a70 | ||
|
|
ed129f057f | ||
|
|
eab5ea01d7 | ||
|
|
3e287b3a26 | ||
|
|
4f33637b43 | ||
|
|
698a1e51ec | ||
|
|
27c0e1186c | ||
|
|
c54c71a3e5 | ||
|
|
3409c00e6f | ||
|
|
f8ef5fab64 | ||
|
|
5b397d455d | ||
|
|
f977558a28 | ||
|
|
c2e156e0e0 | ||
|
|
7aba2938d3 | ||
|
|
d587548250 | ||
|
|
21f9c51556 | ||
|
|
985ceba525 | ||
|
|
e62a4b02e5 | ||
|
|
ff34749572 | ||
|
|
e5804d4a50 | ||
|
|
3956a2b790 | ||
|
|
b33aa52dc2 | ||
|
|
76230db97f | ||
|
|
a66a013ed7 | ||
|
|
f4b02dfdc1 | ||
|
|
4cf218643e | ||
|
|
8f96b69a25 | ||
|
|
d262033ded | ||
|
|
5745eabe69 | ||
|
|
5f18642271 | ||
|
|
88a9278872 | ||
|
|
9bb3ca8169 | ||
|
|
f2f4728489 | ||
|
|
d1b616286f | ||
|
|
df74526f91 | ||
|
|
9f7ae0737a | ||
|
|
1ebb8412c5 | ||
|
|
7b69999c37 | ||
|
|
c7e959a948 | ||
|
|
ba5884e779 | ||
|
|
cdaa5c48db | ||
|
|
bab5c0e907 | ||
|
|
016838fd10 | ||
|
|
75053bf855 | ||
|
|
ae3a6dd2a9 | ||
|
|
6d963fbe8d | ||
|
|
88f6245c84 | ||
|
|
0e7d2f9f93 | ||
|
|
4e6ded1f36 | ||
|
|
d663588491 | ||
|
|
439caf5b79 | ||
|
|
c4ba43ca6f | ||
|
|
20cba2ecd9 | ||
|
|
0ff2e16d69 | ||
|
|
51607ec752 |
@@ -17,7 +17,7 @@ jobs:
|
|||||||
git config --global core.autocrlf false
|
git config --global core.autocrlf false
|
||||||
git config --global core.eol lf
|
git config --global core.eol lf
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
- name: install brotli library on ubuntu
|
- name: install brotli library on ubuntu
|
||||||
if: matrix.os == 'ubuntu-latest'
|
if: matrix.os == 'ubuntu-latest'
|
||||||
run: sudo apt update && sudo apt-get install -y libbrotli-dev
|
run: sudo apt update && sudo apt-get install -y libbrotli-dev
|
||||||
@@ -32,7 +32,7 @@ jobs:
|
|||||||
run: cd test && make fuzz_test
|
run: cd test && make fuzz_test
|
||||||
- name: setup msbuild on windows
|
- name: setup msbuild on windows
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
uses: microsoft/setup-msbuild@v1.0.2
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
- name: make-windows
|
- name: make-windows
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
+50
-26
@@ -6,15 +6,18 @@
|
|||||||
* HTTPLIB_REQUIRE_OPENSSL (default off)
|
* HTTPLIB_REQUIRE_OPENSSL (default off)
|
||||||
* HTTPLIB_REQUIRE_ZLIB (default off)
|
* HTTPLIB_REQUIRE_ZLIB (default off)
|
||||||
* HTTPLIB_USE_BROTLI_IF_AVAILABLE (default on)
|
* HTTPLIB_USE_BROTLI_IF_AVAILABLE (default on)
|
||||||
|
* HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN (default on)
|
||||||
* HTTPLIB_REQUIRE_BROTLI (default off)
|
* HTTPLIB_REQUIRE_BROTLI (default off)
|
||||||
* HTTPLIB_COMPILE (default off)
|
* HTTPLIB_COMPILE (default off)
|
||||||
|
* HTTPLIB_INSTALL (default on)
|
||||||
|
* HTTPLIB_TEST (default off)
|
||||||
* BROTLI_USE_STATIC_LIBS - tells Cmake to use the static Brotli libs (only works if you have them installed).
|
* BROTLI_USE_STATIC_LIBS - tells Cmake to use the static Brotli libs (only works if you have them installed).
|
||||||
* OPENSSL_USE_STATIC_LIBS - tells Cmake to use the static OpenSSL libs (only works if you have them installed).
|
* OPENSSL_USE_STATIC_LIBS - tells Cmake to use the static OpenSSL libs (only works if you have them installed).
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
After installation with Cmake, a find_package(httplib) is available.
|
After installation with Cmake, a find_package(httplib COMPONENTS OpenSSL ZLIB Brotli) is available.
|
||||||
This creates a httplib::httplib target (if found).
|
This creates a httplib::httplib target (if found and if listed components are supported).
|
||||||
It can be linked like so:
|
It can be linked like so:
|
||||||
|
|
||||||
target_link_libraries(your_exe httplib::httplib)
|
target_link_libraries(your_exe httplib::httplib)
|
||||||
@@ -42,6 +45,7 @@
|
|||||||
* HTTPLIB_IS_USING_OPENSSL - a bool for if OpenSSL support is enabled.
|
* HTTPLIB_IS_USING_OPENSSL - a bool for if OpenSSL support is enabled.
|
||||||
* HTTPLIB_IS_USING_ZLIB - a bool for if ZLIB support is enabled.
|
* HTTPLIB_IS_USING_ZLIB - a bool for if ZLIB support is enabled.
|
||||||
* HTTPLIB_IS_USING_BROTLI - a bool for if Brotli support is enabled.
|
* HTTPLIB_IS_USING_BROTLI - a bool for if Brotli support is enabled.
|
||||||
|
* HTTPLIB_IS_USING_CERTS_FROM_MACOSX_KEYCHAIN - a bool for if support of loading system certs from the Apple Keychain is enabled.
|
||||||
* HTTPLIB_IS_COMPILED - a bool for if the library is compiled, or otherwise header-only.
|
* HTTPLIB_IS_COMPILED - a bool for if the library is compiled, or otherwise header-only.
|
||||||
* HTTPLIB_INCLUDE_DIR - the root path to httplib's header (e.g. /usr/include).
|
* HTTPLIB_INCLUDE_DIR - the root path to httplib's header (e.g. /usr/include).
|
||||||
* HTTPLIB_LIBRARY - the full path to the library if compiled (e.g. /usr/lib/libhttplib.so).
|
* HTTPLIB_LIBRARY - the full path to the library if compiled (e.g. /usr/lib/libhttplib.so).
|
||||||
@@ -71,6 +75,10 @@ string(REGEX MATCH "([0-9]+\\.?)+" _httplib_version "${_raw_version_string}")
|
|||||||
|
|
||||||
project(httplib VERSION ${_httplib_version} LANGUAGES CXX)
|
project(httplib VERSION ${_httplib_version} LANGUAGES CXX)
|
||||||
|
|
||||||
|
# Lets you disable C++ exception during CMake configure time.
|
||||||
|
# The value is used in the install CMake config file.
|
||||||
|
option(HTTPLIB_NO_EXCEPTIONS "Disable the use of C++ exceptions" OFF)
|
||||||
|
|
||||||
# Change as needed to set an OpenSSL minimum version.
|
# Change as needed to set an OpenSSL minimum version.
|
||||||
# This is used in the installed Cmake config file.
|
# This is used in the installed Cmake config file.
|
||||||
set(_HTTPLIB_OPENSSL_MIN_VER "1.1.1")
|
set(_HTTPLIB_OPENSSL_MIN_VER "1.1.1")
|
||||||
@@ -78,19 +86,22 @@ set(_HTTPLIB_OPENSSL_MIN_VER "1.1.1")
|
|||||||
# Allow for a build to require OpenSSL to pass, instead of just being optional
|
# Allow for a build to require OpenSSL to pass, instead of just being optional
|
||||||
option(HTTPLIB_REQUIRE_OPENSSL "Requires OpenSSL to be found & linked, or fails build." OFF)
|
option(HTTPLIB_REQUIRE_OPENSSL "Requires OpenSSL to be found & linked, or fails build." OFF)
|
||||||
option(HTTPLIB_REQUIRE_ZLIB "Requires ZLIB to be found & linked, or fails build." OFF)
|
option(HTTPLIB_REQUIRE_ZLIB "Requires ZLIB to be found & linked, or fails build." OFF)
|
||||||
# Allow for a build to casually enable OpenSSL/ZLIB support, but silenty continue if not found.
|
# Allow for a build to casually enable OpenSSL/ZLIB support, but silently continue if not found.
|
||||||
# Make these options so their automatic use can be specifically disabled (as needed)
|
# Make these options so their automatic use can be specifically disabled (as needed)
|
||||||
option(HTTPLIB_USE_OPENSSL_IF_AVAILABLE "Uses OpenSSL (if available) to enable HTTPS support." ON)
|
option(HTTPLIB_USE_OPENSSL_IF_AVAILABLE "Uses OpenSSL (if available) to enable HTTPS support." ON)
|
||||||
option(HTTPLIB_USE_ZLIB_IF_AVAILABLE "Uses ZLIB (if available) to enable Zlib compression support." ON)
|
option(HTTPLIB_USE_ZLIB_IF_AVAILABLE "Uses ZLIB (if available) to enable Zlib compression support." ON)
|
||||||
# Lets you compile the program as a regular library instead of header-only
|
# Lets you compile the program as a regular library instead of header-only
|
||||||
option(HTTPLIB_COMPILE "If ON, uses a Python script to split the header into a compilable header & source file (requires Python v3)." OFF)
|
option(HTTPLIB_COMPILE "If ON, uses a Python script to split the header into a compilable header & source file (requires Python v3)." OFF)
|
||||||
|
# Lets you disable the installation (useful when fetched from another CMake project)
|
||||||
|
option(HTTPLIB_INSTALL "Enables the installation target" ON)
|
||||||
# Just setting this variable here for people building in-tree
|
# Just setting this variable here for people building in-tree
|
||||||
if(HTTPLIB_COMPILE)
|
if(HTTPLIB_COMPILE)
|
||||||
set(HTTPLIB_IS_COMPILED TRUE)
|
set(HTTPLIB_IS_COMPILED TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
option(HTTPLIB_TEST "Enables testing and builds tests" OFF)
|
||||||
option(HTTPLIB_REQUIRE_BROTLI "Requires Brotli to be found & linked, or fails build." OFF)
|
option(HTTPLIB_REQUIRE_BROTLI "Requires Brotli to be found & linked, or fails build." OFF)
|
||||||
option(HTTPLIB_USE_BROTLI_IF_AVAILABLE "Uses Brotli (if available) to enable Brotli decompression support." ON)
|
option(HTTPLIB_USE_BROTLI_IF_AVAILABLE "Uses Brotli (if available) to enable Brotli decompression support." ON)
|
||||||
|
option(HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN "Enable feature to load system certs from the Apple Keychain." ON)
|
||||||
# Defaults to static library
|
# Defaults to static library
|
||||||
option(BUILD_SHARED_LIBS "Build the library as a shared library instead of static. Has no effect if using header-only." OFF)
|
option(BUILD_SHARED_LIBS "Build the library as a shared library instead of static. Has no effect if using header-only." OFF)
|
||||||
if (BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE)
|
if (BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE)
|
||||||
@@ -109,7 +120,7 @@ elseif(HTTPLIB_USE_OPENSSL_IF_AVAILABLE)
|
|||||||
find_package(OpenSSL ${_HTTPLIB_OPENSSL_MIN_VER} COMPONENTS Crypto SSL QUIET)
|
find_package(OpenSSL ${_HTTPLIB_OPENSSL_MIN_VER} COMPONENTS Crypto SSL QUIET)
|
||||||
endif()
|
endif()
|
||||||
# Just setting this variable here for people building in-tree
|
# Just setting this variable here for people building in-tree
|
||||||
if(OPENSSL_FOUND)
|
if(OPENSSL_FOUND AND NOT DEFINED HTTPLIB_IS_USING_OPENSSL)
|
||||||
set(HTTPLIB_IS_USING_OPENSSL TRUE)
|
set(HTTPLIB_IS_USING_OPENSSL TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -136,6 +147,10 @@ if(Brotli_FOUND)
|
|||||||
set(HTTPLIB_IS_USING_BROTLI TRUE)
|
set(HTTPLIB_IS_USING_BROTLI TRUE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN)
|
||||||
|
set(HTTPLIB_IS_USING_CERTS_FROM_MACOSX_KEYCHAIN TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Used for default, common dirs that the end-user can change (if needed)
|
# Used for default, common dirs that the end-user can change (if needed)
|
||||||
# like CMAKE_INSTALL_INCLUDEDIR or CMAKE_INSTALL_DATADIR
|
# like CMAKE_INSTALL_INCLUDEDIR or CMAKE_INSTALL_DATADIR
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
@@ -205,6 +220,8 @@ target_link_libraries(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
|
|||||||
$<$<PLATFORM_ID:Windows>:ws2_32>
|
$<$<PLATFORM_ID:Windows>:ws2_32>
|
||||||
$<$<PLATFORM_ID:Windows>:crypt32>
|
$<$<PLATFORM_ID:Windows>:crypt32>
|
||||||
$<$<PLATFORM_ID:Windows>:cryptui>
|
$<$<PLATFORM_ID:Windows>:cryptui>
|
||||||
|
# Needed for API from MacOS Security framework
|
||||||
|
"$<$<AND:$<PLATFORM_ID:Darwin>,$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>,$<BOOL:${HTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN}>>:-framework CoreFoundation -framework Security>"
|
||||||
# Can't put multiple targets in a single generator expression or it bugs out.
|
# Can't put multiple targets in a single generator expression or it bugs out.
|
||||||
$<$<BOOL:${HTTPLIB_IS_USING_BROTLI}>:Brotli::common>
|
$<$<BOOL:${HTTPLIB_IS_USING_BROTLI}>:Brotli::common>
|
||||||
$<$<BOOL:${HTTPLIB_IS_USING_BROTLI}>:Brotli::encoder>
|
$<$<BOOL:${HTTPLIB_IS_USING_BROTLI}>:Brotli::encoder>
|
||||||
@@ -216,9 +233,11 @@ target_link_libraries(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
|
|||||||
|
|
||||||
# Set the definitions to enable optional features
|
# Set the definitions to enable optional features
|
||||||
target_compile_definitions(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
|
target_compile_definitions(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
|
||||||
|
$<$<BOOL:${HTTPLIB_NO_EXCEPTIONS}>:CPPHTTPLIB_NO_EXCEPTIONS>
|
||||||
$<$<BOOL:${HTTPLIB_IS_USING_BROTLI}>:CPPHTTPLIB_BROTLI_SUPPORT>
|
$<$<BOOL:${HTTPLIB_IS_USING_BROTLI}>:CPPHTTPLIB_BROTLI_SUPPORT>
|
||||||
$<$<BOOL:${HTTPLIB_IS_USING_ZLIB}>:CPPHTTPLIB_ZLIB_SUPPORT>
|
$<$<BOOL:${HTTPLIB_IS_USING_ZLIB}>:CPPHTTPLIB_ZLIB_SUPPORT>
|
||||||
$<$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>:CPPHTTPLIB_OPENSSL_SUPPORT>
|
$<$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>:CPPHTTPLIB_OPENSSL_SUPPORT>
|
||||||
|
$<$<AND:$<PLATFORM_ID:Darwin>,$<BOOL:${HTTPLIB_IS_USING_OPENSSL}>,$<BOOL:${HTTPLIB_IS_USING_CERTS_FROM_MACOSX_KEYCHAIN}>>:CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN>
|
||||||
)
|
)
|
||||||
|
|
||||||
# CMake configuration files installation directory
|
# CMake configuration files installation directory
|
||||||
@@ -232,20 +251,18 @@ configure_package_config_file("${PROJECT_NAME}Config.cmake.in"
|
|||||||
INSTALL_DESTINATION "${_TARGET_INSTALL_CMAKEDIR}"
|
INSTALL_DESTINATION "${_TARGET_INSTALL_CMAKEDIR}"
|
||||||
# Passes the includedir install path
|
# Passes the includedir install path
|
||||||
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR
|
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR
|
||||||
# There aren't any components, so don't use the macro
|
|
||||||
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if(HTTPLIB_COMPILE)
|
if(HTTPLIB_COMPILE)
|
||||||
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
|
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
# Example: if you find_package(httplib 0.5.4)
|
# Example: if you find_package(httplib 0.5.4)
|
||||||
# then anything >= 0.5 and <= 1.0 is accepted
|
# then anything >= 0.5.4 and < 0.6 is accepted
|
||||||
COMPATIBILITY SameMinorVersion
|
COMPATIBILITY SameMinorVersion
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
|
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
# Example: if you find_package(httplib 0.5.4)
|
# Example: if you find_package(httplib 0.5.4)
|
||||||
# then anything >= 0.5 and <= 1.0 is accepted
|
# then anything >= 0.5.4 and < 0.6 is accepted
|
||||||
COMPATIBILITY SameMinorVersion
|
COMPATIBILITY SameMinorVersion
|
||||||
# Tells Cmake that it's a header-only lib
|
# Tells Cmake that it's a header-only lib
|
||||||
# Mildly useful for end-users :)
|
# Mildly useful for end-users :)
|
||||||
@@ -253,28 +270,35 @@ else()
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Creates the export httplibTargets.cmake
|
if(HTTPLIB_INSTALL)
|
||||||
# This is strictly what holds compilation requirements
|
# Creates the export httplibTargets.cmake
|
||||||
# and linkage information (doesn't find deps though).
|
# This is strictly what holds compilation requirements
|
||||||
install(TARGETS ${PROJECT_NAME}
|
# and linkage information (doesn't find deps though).
|
||||||
EXPORT httplibTargets
|
install(TARGETS ${PROJECT_NAME}
|
||||||
)
|
EXPORT httplibTargets
|
||||||
|
)
|
||||||
|
|
||||||
install(FILES "${_httplib_build_includedir}/httplib.h" TYPE INCLUDE)
|
install(FILES "${_httplib_build_includedir}/httplib.h" TYPE INCLUDE)
|
||||||
|
|
||||||
install(FILES
|
install(FILES
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
# Install it so it can be used later by the httplibConfig.cmake file.
|
# Install it so it can be used later by the httplibConfig.cmake file.
|
||||||
# Put it in the same dir as our config file instead of a global path so we don't potentially stomp on other packages.
|
# Put it in the same dir as our config file instead of a global path so we don't potentially stomp on other packages.
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindBrotli.cmake"
|
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindBrotli.cmake"
|
||||||
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
|
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
# NOTE: This path changes depending on if it's on Windows or Linux
|
# NOTE: This path changes depending on if it's on Windows or Linux
|
||||||
install(EXPORT httplibTargets
|
install(EXPORT httplibTargets
|
||||||
# Puts the targets into the httplib namespace
|
# Puts the targets into the httplib namespace
|
||||||
# So this makes httplib::httplib linkable after doing find_package(httplib)
|
# So this makes httplib::httplib linkable after doing find_package(httplib)
|
||||||
NAMESPACE ${PROJECT_NAME}::
|
NAMESPACE ${PROJECT_NAME}::
|
||||||
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
|
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
|
||||||
)
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(HTTPLIB_TEST)
|
||||||
|
include(CTest)
|
||||||
|
add_subdirectory(test)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ SSL support is available with `CPPHTTPLIB_OPENSSL_SUPPORT`. `libssl` and `libcry
|
|||||||
|
|
||||||
NOTE: cpp-httplib currently supports only version 1.1.1 and 3.0.
|
NOTE: cpp-httplib currently supports only version 1.1.1 and 3.0.
|
||||||
|
|
||||||
|
NOTE for macOS: cpp-httplib now can use system certs with `CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN`. `CoreFoundation` and `Security` should be linked with `-framework`.
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
#include "path/to/httplib.h"
|
#include "path/to/httplib.h"
|
||||||
@@ -74,7 +76,7 @@ cli.set_ca_cert_path("./ca-bundle.crt");
|
|||||||
cli.enable_server_certificate_verification(false);
|
cli.enable_server_certificate_verification(false);
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: When using SSL, it seems impossible to avoid SIGPIPE in all cases, since on some operating systems, SIGPIPE can only be suppressed on a per-message basis, but there is no way to make the OpenSSL library do so for its internal communications. If your program needs to avoid being terminated on SIGPIPE, the only fully general way might be to set up a signal handler for SIGPIPE to handle or ignore it yourself.
|
NOTE: When using SSL, it seems impossible to avoid SIGPIPE in all cases, since on some operating systems, SIGPIPE can only be suppressed on a per-message basis, but there is no way to make the OpenSSL library do so for its internal communications. If your program needs to avoid being terminated on SIGPIPE, the only fully general way might be to set up a signal handler for SIGPIPE to handle or ignore it yourself.
|
||||||
|
|
||||||
Server
|
Server
|
||||||
------
|
------
|
||||||
@@ -92,11 +94,20 @@ int main(void)
|
|||||||
res.set_content("Hello World!", "text/plain");
|
res.set_content("Hello World!", "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Match the request path against a regular expression
|
||||||
|
// and extract its captures
|
||||||
svr.Get(R"(/numbers/(\d+))", [&](const Request& req, Response& res) {
|
svr.Get(R"(/numbers/(\d+))", [&](const Request& req, Response& res) {
|
||||||
auto numbers = req.matches[1];
|
auto numbers = req.matches[1];
|
||||||
res.set_content(numbers, "text/plain");
|
res.set_content(numbers, "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Capture the second segment of the request path as "id" path param
|
||||||
|
svr.Get("/users/:id", [&](const Request& req, Response& res) {
|
||||||
|
auto user_id = req.path_params.at("id");
|
||||||
|
res.set_content(user_id, "text/plain");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Extract values from HTTP headers and URL query params
|
||||||
svr.Get("/body-header-param", [](const Request& req, Response& res) {
|
svr.Get("/body-header-param", [](const Request& req, Response& res) {
|
||||||
if (req.has_header("Content-Length")) {
|
if (req.has_header("Content-Length")) {
|
||||||
auto val = req.get_header_value("Content-Length");
|
auto val = req.get_header_value("Content-Length");
|
||||||
@@ -179,6 +190,8 @@ The followings are built-in mappings:
|
|||||||
| webm | video/webm | zip | application/zip |
|
| webm | video/webm | zip | application/zip |
|
||||||
| mp3 | audio/mp3 | wasm | application/wasm |
|
| mp3 | audio/mp3 | wasm | application/wasm |
|
||||||
|
|
||||||
|
NOTE: These static file server methods are not thread-safe.
|
||||||
|
|
||||||
### File request handler
|
### File request handler
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -188,8 +201,6 @@ svr.set_file_request_handler([](const Request &req, Response &res) {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
NOTE: These static file server methods are not thread-safe.
|
|
||||||
|
|
||||||
### Logging
|
### Logging
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -301,7 +312,7 @@ svr.Get("/stream", [&](const Request &req, Response &res) {
|
|||||||
res.set_content_provider(
|
res.set_content_provider(
|
||||||
data->size(), // Content length
|
data->size(), // Content length
|
||||||
"text/plain", // Content type
|
"text/plain", // Content type
|
||||||
[data](size_t offset, size_t length, DataSink &sink) {
|
[&, data](size_t offset, size_t length, DataSink &sink) {
|
||||||
const auto &d = *data;
|
const auto &d = *data;
|
||||||
sink.write(&d[offset], std::min(length, DATA_CHUNK_SIZE));
|
sink.write(&d[offset], std::min(length, DATA_CHUNK_SIZE));
|
||||||
return true; // return 'false' if you want to cancel the process.
|
return true; // return 'false' if you want to cancel the process.
|
||||||
@@ -346,6 +357,27 @@ svr.Get("/chunked", [&](const Request& req, Response& res) {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
With trailer:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
svr.Get("/chunked", [&](const Request& req, Response& res) {
|
||||||
|
res.set_header("Trailer", "Dummy1, Dummy2");
|
||||||
|
res.set_chunked_content_provider(
|
||||||
|
"text/plain",
|
||||||
|
[](size_t offset, DataSink &sink) {
|
||||||
|
sink.write("123", 3);
|
||||||
|
sink.write("345", 3);
|
||||||
|
sink.write("789", 3);
|
||||||
|
sink.done_with_trailer({
|
||||||
|
{"Dummy1", "DummyVal1"},
|
||||||
|
{"Dummy2", "DummyVal2"}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
### 'Expect: 100-continue' handler
|
### 'Expect: 100-continue' handler
|
||||||
|
|
||||||
By default, the server sends a `100 Continue` response for an `Expect: 100-continue` header.
|
By default, the server sends a `100 Continue` response for an `Expect: 100-continue` header.
|
||||||
@@ -493,6 +525,10 @@ auto res = cli.Get("/hi", headers);
|
|||||||
```
|
```
|
||||||
or
|
or
|
||||||
```c++
|
```c++
|
||||||
|
auto res = cli.Get("/hi", {{"Accept-Encoding", "gzip, deflate"}});
|
||||||
|
```
|
||||||
|
or
|
||||||
|
```c++
|
||||||
cli.set_default_headers({
|
cli.set_default_headers({
|
||||||
{ "Accept-Encoding", "gzip, deflate" }
|
{ "Accept-Encoding", "gzip, deflate" }
|
||||||
});
|
});
|
||||||
@@ -808,14 +844,14 @@ Include `httplib.h` before `Windows.h` or include `Windows.h` by defining `WIN32
|
|||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: cpp-httplib officially supports only the latest Visual Studio. It might work with former versions of Visual Studio, but I can no longer verify it. Pull requests are always welcome for the older versions of Visual Studio unless they break the C++11 conformance.
|
NOTE: cpp-httplib officially supports only the latest Visual Studio. It might work with former versions of Visual Studio, but I can no longer verify it. Pull requests are always welcome for the older versions of Visual Studio unless they break the C++11 conformance.
|
||||||
|
|
||||||
Note: Windows 8 or lower, Visual Studio 2013 or lower, and Cygwin on Windows are not supported.
|
NOTE: Windows 8 or lower, Visual Studio 2013 or lower, and Cygwin on Windows are not supported.
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|
||||||
MIT license (© 2022 Yuji Hirose)
|
MIT license (© 2023 Yuji Hirose)
|
||||||
|
|
||||||
Special Thanks To
|
Special Thanks To
|
||||||
-----------------
|
-----------------
|
||||||
|
|||||||
+8
-1
@@ -8,12 +8,19 @@ OPENSSL_DIR = $(PREFIX)/opt/openssl@1.1
|
|||||||
#OPENSSL_DIR = $(PREFIX)/opt/openssl@3
|
#OPENSSL_DIR = $(PREFIX)/opt/openssl@3
|
||||||
OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR)/include -L$(OPENSSL_DIR)/lib -lssl -lcrypto
|
OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR)/include -L$(OPENSSL_DIR)/lib -lssl -lcrypto
|
||||||
|
|
||||||
|
ifneq ($(OS), Windows_NT)
|
||||||
|
UNAME_S := $(shell uname -s)
|
||||||
|
ifeq ($(UNAME_S), Darwin)
|
||||||
|
OPENSSL_SUPPORT += -framework CoreFoundation -framework Security
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
|
ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
|
||||||
|
|
||||||
BROTLI_DIR = $(PREFIX)/opt/brotli
|
BROTLI_DIR = $(PREFIX)/opt/brotli
|
||||||
BROTLI_SUPPORT = -DCPPHTTPLIB_BROTLI_SUPPORT -I$(BROTLI_DIR)/include -L$(BROTLI_DIR)/lib -lbrotlicommon -lbrotlienc -lbrotlidec
|
BROTLI_SUPPORT = -DCPPHTTPLIB_BROTLI_SUPPORT -I$(BROTLI_DIR)/include -L$(BROTLI_DIR)/lib -lbrotlicommon -lbrotlienc -lbrotlidec
|
||||||
|
|
||||||
all: server client hello simplecli simplesvr upload redirect ssesvr ssecli benchmark
|
all: server client hello simplecli simplesvr upload redirect ssesvr ssecli benchmark issue
|
||||||
|
|
||||||
server : server.cc ../httplib.h Makefile
|
server : server.cc ../httplib.h Makefile
|
||||||
$(CXX) -o server $(CXXFLAGS) server.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT) $(BROTLI_SUPPORT)
|
$(CXX) -o server $(CXXFLAGS) server.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT) $(BROTLI_SUPPORT)
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ public:
|
|||||||
unique_lock<mutex> lk(m_);
|
unique_lock<mutex> lk(m_);
|
||||||
int id = id_;
|
int id = id_;
|
||||||
cv_.wait(lk, [&] { return cid_ == id; });
|
cv_.wait(lk, [&] { return cid_ == id; });
|
||||||
if (sink->is_writable()) { sink->write(message_.data(), message_.size()); }
|
sink->write(message_.data(), message_.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_event(const string &message) {
|
void send_event(const string &message) {
|
||||||
|
|||||||
+17
-8
@@ -12,19 +12,19 @@ set(HTTPLIB_VERSION @PROJECT_VERSION@)
|
|||||||
include(CMakeFindDependencyMacro)
|
include(CMakeFindDependencyMacro)
|
||||||
|
|
||||||
# We add find_dependency calls here to not make the end-user have to call them.
|
# We add find_dependency calls here to not make the end-user have to call them.
|
||||||
find_dependency(Threads REQUIRED)
|
find_dependency(Threads)
|
||||||
if(@HTTPLIB_IS_USING_OPENSSL@)
|
if(@HTTPLIB_IS_USING_OPENSSL@)
|
||||||
# OpenSSL COMPONENTS were added in Cmake v3.11
|
# OpenSSL COMPONENTS were added in Cmake v3.11
|
||||||
if(CMAKE_VERSION VERSION_LESS "3.11")
|
if(CMAKE_VERSION VERSION_LESS "3.11")
|
||||||
find_dependency(OpenSSL @_HTTPLIB_OPENSSL_MIN_VER@ REQUIRED)
|
find_dependency(OpenSSL @_HTTPLIB_OPENSSL_MIN_VER@)
|
||||||
else()
|
else()
|
||||||
# Once the COMPONENTS were added, they were made optional when not specified.
|
# Once the COMPONENTS were added, they were made optional when not specified.
|
||||||
# Since we use both, we need to search for both.
|
# Since we use both, we need to search for both.
|
||||||
find_dependency(OpenSSL @_HTTPLIB_OPENSSL_MIN_VER@ COMPONENTS Crypto SSL REQUIRED)
|
find_dependency(OpenSSL @_HTTPLIB_OPENSSL_MIN_VER@ COMPONENTS Crypto SSL)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if(@HTTPLIB_IS_USING_ZLIB@)
|
if(@HTTPLIB_IS_USING_ZLIB@)
|
||||||
find_dependency(ZLIB REQUIRED)
|
find_dependency(ZLIB)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(@HTTPLIB_IS_USING_BROTLI@)
|
if(@HTTPLIB_IS_USING_BROTLI@)
|
||||||
@@ -32,7 +32,7 @@ if(@HTTPLIB_IS_USING_BROTLI@)
|
|||||||
# Note that the FindBrotli.cmake file is installed in the same dir as this file.
|
# Note that the FindBrotli.cmake file is installed in the same dir as this file.
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
set(BROTLI_USE_STATIC_LIBS @BROTLI_USE_STATIC_LIBS@)
|
set(BROTLI_USE_STATIC_LIBS @BROTLI_USE_STATIC_LIBS@)
|
||||||
find_dependency(Brotli COMPONENTS common encoder decoder REQUIRED)
|
find_dependency(Brotli COMPONENTS common encoder decoder)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Mildly useful for end-users
|
# Mildly useful for end-users
|
||||||
@@ -42,10 +42,19 @@ set_and_check(HTTPLIB_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@")
|
|||||||
# This is helpful if you're using Cmake's pre-compiled header feature
|
# This is helpful if you're using Cmake's pre-compiled header feature
|
||||||
set_and_check(HTTPLIB_HEADER_PATH "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@/httplib.h")
|
set_and_check(HTTPLIB_HEADER_PATH "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@/httplib.h")
|
||||||
|
|
||||||
# Brings in the target library
|
# Consider each library support as a "component"
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/httplibTargets.cmake")
|
set(httplib_OpenSSL_FOUND @HTTPLIB_IS_USING_OPENSSL@)
|
||||||
|
set(httplib_ZLIB_FOUND @HTTPLIB_IS_USING_ZLIB@)
|
||||||
|
set(httplib_Brotli_FOUND @HTTPLIB_IS_USING_BROTLI@)
|
||||||
|
|
||||||
# Ouputs a "found httplib /usr/include/httplib.h" message when using find_package(httplib)
|
check_required_components(httplib)
|
||||||
|
|
||||||
|
# Brings in the target library, but only if all required components are found
|
||||||
|
if(NOT DEFINED httplib_FOUND OR httplib_FOUND)
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/httplibTargets.cmake")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Outputs a "found httplib /usr/include/httplib.h" message when using find_package(httplib)
|
||||||
include(FindPackageMessage)
|
include(FindPackageMessage)
|
||||||
if(TARGET httplib::httplib)
|
if(TARGET httplib::httplib)
|
||||||
set(HTTPLIB_FOUND TRUE)
|
set(HTTPLIB_FOUND TRUE)
|
||||||
|
|||||||
@@ -34,6 +34,13 @@ openssl_dep = dependency('openssl', version: '>=1.1.1', required: get_option('cp
|
|||||||
if openssl_dep.found()
|
if openssl_dep.found()
|
||||||
deps += openssl_dep
|
deps += openssl_dep
|
||||||
args += '-DCPPHTTPLIB_OPENSSL_SUPPORT'
|
args += '-DCPPHTTPLIB_OPENSSL_SUPPORT'
|
||||||
|
if host_machine.system() == 'darwin'
|
||||||
|
macosx_keychain_dep = dependency('appleframeworks', modules: ['CoreFoundation', 'Security'], required: get_option('cpp-httplib_macosx_keychain'))
|
||||||
|
if macosx_keychain_dep.found()
|
||||||
|
deps += macosx_keychain_dep
|
||||||
|
args += '-DCPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
zlib_dep = dependency('zlib', required: get_option('cpp-httplib_zlib'))
|
zlib_dep = dependency('zlib', required: get_option('cpp-httplib_zlib'))
|
||||||
|
|||||||
@@ -5,5 +5,6 @@
|
|||||||
option('cpp-httplib_openssl', type: 'feature', value: 'auto', description: 'Enable OpenSSL support')
|
option('cpp-httplib_openssl', type: 'feature', value: 'auto', description: 'Enable OpenSSL support')
|
||||||
option('cpp-httplib_zlib', type: 'feature', value: 'auto', description: 'Enable zlib support')
|
option('cpp-httplib_zlib', type: 'feature', value: 'auto', description: 'Enable zlib support')
|
||||||
option('cpp-httplib_brotli', type: 'feature', value: 'auto', description: 'Enable Brotli support')
|
option('cpp-httplib_brotli', type: 'feature', value: 'auto', description: 'Enable Brotli support')
|
||||||
|
option('cpp-httplib_macosx_keychain', type: 'feature', value: 'auto', description: 'Enable loading certs from the Keychain on Apple devices')
|
||||||
option('cpp-httplib_compile', type: 'boolean', value: false, description: 'Split the header into a compilable header & source file (requires python3)')
|
option('cpp-httplib_compile', type: 'boolean', value: false, description: 'Split the header into a compilable header & source file (requires python3)')
|
||||||
option('cpp-httplib_test', type: 'boolean', value: false, description: 'Build tests')
|
option('cpp-httplib_test', type: 'boolean', value: false, description: 'Build tests')
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
find_package(GTest)
|
||||||
|
|
||||||
|
if(GTest_FOUND)
|
||||||
|
if(NOT TARGET GTest::gtest_main AND TARGET GTest::Main)
|
||||||
|
# CMake <3.20
|
||||||
|
add_library(GTest::gtest_main INTERFACE IMPORTED)
|
||||||
|
target_link_libraries(GTest::gtest_main INTERFACE GTest::Main)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
if(POLICY CMP0135)
|
||||||
|
cmake_policy(SET CMP0135 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
set(BUILD_GMOCK OFF)
|
||||||
|
set(INSTALL_GTEST OFF)
|
||||||
|
set(gtest_force_shared_crt ON)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
gtest
|
||||||
|
URL https://github.com/google/googletest/archive/main.tar.gz
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(gtest)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(httplib-test test.cc)
|
||||||
|
target_compile_options(httplib-test PRIVATE "$<$<CXX_COMPILER_ID:MSVC>:/utf-8;/bigobj>")
|
||||||
|
target_link_libraries(httplib-test PRIVATE httplib GTest::gtest_main)
|
||||||
|
gtest_discover_tests(httplib-test)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/www www
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/www2 www2
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/www3 www3
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_LIST_DIR}/ca-bundle.crt ca-bundle.crt
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_LIST_DIR}/image.jpg image.jpg
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
|
||||||
|
if(HTTPLIB_IS_USING_OPENSSL)
|
||||||
|
find_program(OPENSSL_COMMAND
|
||||||
|
NAMES openssl
|
||||||
|
PATHS ${OPENSSL_INCLUDE_DIR}/../bin
|
||||||
|
REQUIRED
|
||||||
|
)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${OPENSSL_COMMAND} genrsa 2048
|
||||||
|
OUTPUT_FILE key.pem
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${OPENSSL_COMMAND} req -new -batch -config ${CMAKE_CURRENT_LIST_DIR}/test.conf -key key.pem
|
||||||
|
COMMAND ${OPENSSL_COMMAND} x509 -days 3650 -req -signkey key.pem
|
||||||
|
OUTPUT_FILE cert.pem
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${OPENSSL_COMMAND} req -x509 -new -config ${CMAKE_CURRENT_LIST_DIR}/test.conf -key key.pem -sha256 -days 3650 -nodes -out cert2.pem -extensions SAN
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${OPENSSL_COMMAND} genrsa 2048
|
||||||
|
OUTPUT_FILE rootCA.key.pem
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${OPENSSL_COMMAND} req -x509 -new -batch -config ${CMAKE_CURRENT_LIST_DIR}/test.rootCA.conf -key rootCA.key.pem -days 1024
|
||||||
|
OUTPUT_FILE rootCA.cert.pem
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${OPENSSL_COMMAND} genrsa 2048
|
||||||
|
OUTPUT_FILE client.key.pem
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${OPENSSL_COMMAND} req -new -batch -config ${CMAKE_CURRENT_LIST_DIR}/test.conf -key client.key.pem
|
||||||
|
COMMAND ${OPENSSL_COMMAND} x509 -days 370 -req -CA rootCA.cert.pem -CAkey rootCA.key.pem -CAcreateserial
|
||||||
|
OUTPUT_FILE client.cert.pem
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${OPENSSL_COMMAND} genrsa -passout pass:test123! 2048
|
||||||
|
OUTPUT_FILE key_encrypted.pem
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${OPENSSL_COMMAND} req -new -batch -config ${CMAKE_CURRENT_LIST_DIR}/test.conf -key key_encrypted.pem
|
||||||
|
COMMAND ${OPENSSL_COMMAND} x509 -days 3650 -req -signkey key_encrypted.pem
|
||||||
|
OUTPUT_FILE cert_encrypted.pem
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
COMMAND_ERROR_IS_FATAL ANY
|
||||||
|
)
|
||||||
|
endif()
|
||||||
@@ -8,6 +8,13 @@ OPENSSL_DIR = $(PREFIX)/opt/openssl@1.1
|
|||||||
#OPENSSL_DIR = $(PREFIX)/opt/openssl@3
|
#OPENSSL_DIR = $(PREFIX)/opt/openssl@3
|
||||||
OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR)/include -L$(OPENSSL_DIR)/lib -lssl -lcrypto
|
OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR)/include -L$(OPENSSL_DIR)/lib -lssl -lcrypto
|
||||||
|
|
||||||
|
ifneq ($(OS), Windows_NT)
|
||||||
|
UNAME_S := $(shell uname -s)
|
||||||
|
ifeq ($(UNAME_S), Darwin)
|
||||||
|
OPENSSL_SUPPORT += -DCPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN -framework CoreFoundation -framework Security
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
|
ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
|
||||||
|
|
||||||
BROTLI_DIR = $(PREFIX)/opt/brotli
|
BROTLI_DIR = $(PREFIX)/opt/brotli
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// Forward declare the "fuzz target" interface.
|
// Forward declare the "fuzz target" interface.
|
||||||
// We deliberately keep this inteface simple and header-free.
|
// We deliberately keep this interface simple and header-free.
|
||||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
||||||
|
|
||||||
// It reads all files passed as parameters and feeds their contents
|
// It reads all files passed as parameters and feeds their contents
|
||||||
|
|||||||
+8
-1
@@ -86,6 +86,12 @@ subdir(join_paths('www', 'dir'))
|
|||||||
subdir(join_paths('www2', 'dir'))
|
subdir(join_paths('www2', 'dir'))
|
||||||
subdir(join_paths('www3', 'dir'))
|
subdir(join_paths('www3', 'dir'))
|
||||||
|
|
||||||
|
# GoogleTest 1.13.0 requires C++14
|
||||||
|
test_options = []
|
||||||
|
if gtest_dep.version().version_compare('>=1.13.0')
|
||||||
|
test_options += 'cpp_std=c++14'
|
||||||
|
endif
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'main',
|
'main',
|
||||||
executable(
|
executable(
|
||||||
@@ -94,7 +100,8 @@ test(
|
|||||||
dependencies: [
|
dependencies: [
|
||||||
cpp_httplib_dep,
|
cpp_httplib_dep,
|
||||||
gtest_dep
|
gtest_dep
|
||||||
]
|
],
|
||||||
|
override_options: test_options
|
||||||
),
|
),
|
||||||
depends: [
|
depends: [
|
||||||
key_pem,
|
key_pem,
|
||||||
|
|||||||
+1139
-325
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -193,7 +193,7 @@ void DigestAuthTestFromHTTPWatch(T& cli) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: Until httpbin.org fixes issue #46, the following test is commented
|
// NOTE: Until httpbin.org fixes issue #46, the following test is commented
|
||||||
// out. Plese see https://httpbin.org/digest-auth/auth/hello/world
|
// out. Please see https://httpbin.org/digest-auth/auth/hello/world
|
||||||
// cli.set_digest_auth("bad", "world");
|
// cli.set_digest_auth("bad", "world");
|
||||||
// for (auto path : paths) {
|
// for (auto path : paths) {
|
||||||
// auto res = cli.Get(path.c_str());
|
// auto res = cli.Get(path.c_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user