Skip to content

Commit 86b94fb

Browse files
authored
TLS HTTP Client (#2260)
* TLS HTTP Client * Update CMakeLists.txt * Update gcc-x86.yml * Fixes * Update http_client.hpp * HTTPS Trust Store Configuration
1 parent f34df72 commit 86b94fb

File tree

9 files changed

+1844
-236
lines changed

9 files changed

+1844
-236
lines changed

.github/workflows/gcc-x86.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,9 @@ jobs:
3939
sudo apt update
4040
sudo apt-get install -y gcc-${{matrix.gcc}}-multilib g++-${{matrix.gcc}}-multilib libc6-dev-i386
4141
42-
- name: Remove HTTPS test (requires OpenSSL)
43-
run: |
44-
# Remove the https_test from tests CMakeLists.txt for this build
45-
sed -i '/add_subdirectory(https_test)/d' tests/networking_tests/CMakeLists.txt
46-
4742
- name: Configure CMake
4843
run: |
49-
CXXFLAGS="-g3 -m32" cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_STANDARD=${{matrix.std}}
44+
CXXFLAGS="-g3 -m32" cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_STANDARD=${{matrix.std}} -Dglaze_BUILD_SSL_TESTS=OFF
5045
5146
- name: Build
5247
run: cmake --build build -j $(nproc)

docs/networking/http-client.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,44 @@ int main() {
3838
- **Thread-Safe**: Multiple threads can safely use the same client instance
3939
- **Error Handling**: Uses `std::expected` for clean error handling
4040

41+
## HTTPS Trust Store Configuration
42+
43+
When using HTTPS, certificate verification depends on your OpenSSL trust store configuration.
44+
To simplify setup, `http_client` provides:
45+
46+
```cpp
47+
std::expected<void, std::error_code> configure_system_ca_certificates(
48+
std::optional<std::string_view> cert_bundle_file = std::nullopt
49+
);
50+
```
51+
52+
Fallback order:
53+
54+
1. Explicit `cert_bundle_file` argument (if provided)
55+
2. `SSL_CERT_FILE` environment variable
56+
3. `SSL_CERT_DIR` environment variable
57+
4. OpenSSL default verify paths (`set_default_verify_paths`)
58+
59+
Example:
60+
61+
```cpp
62+
glz::http_client client;
63+
64+
if (auto ec = client.configure_system_ca_certificates("/path/to/cert.pem"); !ec) {
65+
std::cerr << "Failed to configure CA trust roots: " << ec.error().message() << '\n';
66+
return;
67+
}
68+
69+
auto response = client.get("https://example.com");
70+
```
71+
72+
Notes:
73+
74+
- On macOS with Homebrew OpenSSL, you may need to point `SSL_CERT_FILE` at Homebrew's CA bundle
75+
(commonly `/opt/homebrew/etc/ca-certificates/cert.pem`).
76+
- OpenSSL certificate lookup behavior is platform/package-manager dependent; explicit configuration is recommended
77+
for reproducible deployments.
78+
4179
## Synchronous Methods
4280

4381
### GET Request

0 commit comments

Comments
 (0)