diff options
| author | Stefan Boberg <[email protected]> | 2026-03-10 17:27:26 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-10 17:27:26 +0100 |
| commit | d0a07e555577dcd4a8f55f1b45d9e8e4e6366ab7 (patch) | |
| tree | 2dfe1e3e0b620043d358e0b7f8bdf8320d985491 /src/zenhttp/servers/asio_socket_traits.h | |
| parent | changelog entry which was inadvertently omitted from PR merge (diff) | |
| download | zen-d0a07e555577dcd4a8f55f1b45d9e8e4e6366ab7.tar.xz zen-d0a07e555577dcd4a8f55f1b45d9e8e4e6366ab7.zip | |
HttpClient using libcurl, Unix Sockets for HTTP. HTTPS support (#770)
The main goal of this change is to eliminate the cpr back-end altogether and replace it with the curl implementation. I would expect to drop cpr as soon as we feel happy with the libcurl back-end. That would leave us with a direct dependency on libcurl only, and cpr can be eliminated as a dependency.
### HttpClient Backend Overhaul
- Implemented a new **libcurl-based HttpClient** backend (`httpclientcurl.cpp`, ~2000 lines)
as an alternative to the cpr-based one
- Made HttpClient backend **configurable at runtime** via constructor arguments
and `-httpclient=...` CLI option (for zen, zenserver, and tests)
- Extended HttpClient test suite to cover multipart/content-range scenarios
### Unix Domain Socket Support
- Added Unix domain socket support to **httpasio** (server side)
- Added Unix domain socket support to **HttpClient**
- Added Unix domain socket support to **HttpWsClient** (WebSocket client)
- Templatized `HttpServerConnectionT<SocketType>` and `WsAsioConnectionT<SocketType>`
to handle TCP, Unix, and SSL sockets uniformly via `if constexpr` dispatch
### HTTPS Support
- Added **preliminary HTTPS support to httpasio** (for Mac/Linux via OpenSSL)
- Added **basic HTTPS support for http.sys** (Windows)
- Implemented HTTPS test for httpasio
- Split `InitializeServer` into smaller sub-functions for http.sys
### Other Notable Changes
- Improved **zenhttp-test stability** with dynamic port allocation
- Enhanced port retry logic in http.sys (handles ERROR_ACCESS_DENIED)
- Fatal signal/exception handlers for backtrace generation in tests
- Added `zen bench http` subcommand to exercise network + HTTP client/server communication stack
Diffstat (limited to 'src/zenhttp/servers/asio_socket_traits.h')
| -rw-r--r-- | src/zenhttp/servers/asio_socket_traits.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/zenhttp/servers/asio_socket_traits.h b/src/zenhttp/servers/asio_socket_traits.h new file mode 100644 index 000000000..25aeaa24e --- /dev/null +++ b/src/zenhttp/servers/asio_socket_traits.h @@ -0,0 +1,54 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +ZEN_THIRD_PARTY_INCLUDES_START +#include <asio.hpp> +#if ZEN_USE_OPENSSL +# include <asio/ssl.hpp> +#endif +ZEN_THIRD_PARTY_INCLUDES_END + +namespace zen::asio_http { + +/** + * Traits for abstracting socket shutdown/close across plain TCP, Unix domain, and SSL sockets. + * SSL sockets need lowest_layer() access and have different shutdown semantics. + */ +template<typename SocketType> +struct SocketTraits +{ + /// SSL sockets cannot use zero-copy file send (TransmitFile/sendfile) because + /// those bypass the encryption layer. This flag lets templated code fall back + /// to reading-into-memory for SSL connections. + static constexpr bool IsSslSocket = false; + + static void ShutdownReceive(SocketType& S, std::error_code& Ec) { S.shutdown(asio::socket_base::shutdown_receive, Ec); } + + static void ShutdownBoth(SocketType& S, std::error_code& Ec) { S.shutdown(asio::socket_base::shutdown_both, Ec); } + + static void Close(SocketType& S, std::error_code& Ec) { S.close(Ec); } +}; + +#if ZEN_USE_OPENSSL +using SslSocket = asio::ssl::stream<asio::ip::tcp::socket>; + +template<> +struct SocketTraits<SslSocket> +{ + static constexpr bool IsSslSocket = true; + + static void ShutdownReceive(SslSocket& S, std::error_code& Ec) { S.lowest_layer().shutdown(asio::socket_base::shutdown_receive, Ec); } + + static void ShutdownBoth(SslSocket& S, std::error_code& Ec) + { + // Best-effort SSL close_notify, then TCP shutdown + S.shutdown(Ec); + S.lowest_layer().shutdown(asio::socket_base::shutdown_both, Ec); + } + + static void Close(SslSocket& S, std::error_code& Ec) { S.lowest_layer().close(Ec); } +}; +#endif + +} // namespace zen::asio_http |