From 08a03534af459da00d57e5ad66c08a86954cee90 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Mon, 7 Jul 2025 16:03:37 +0100 Subject: [PATCH] Meta+RequestServer: Enable HTTP/3 for curl This adds an overlay port for curl that adds the features required for HTTP/3. This is not quite compatible with the upstream vcpkg.json, because enabling HTTP/2 makes it use the default SSL backend, which is sectransp for macOS and schannel on Windows. These backends are not compatible with ngtcp2. Additionally, we can not build curl with multiple SSL backends when using ngtcp2. I couldn't find a way to selectively disable/enable dependencies based on what features are enabled, so I made HTTP/2 pick OpenSSL in our overlay port. Upstream vcpkg will likely want to support wolfSSL and GnuTLS backends for ngtcp2, so they'll be additional work to get this into upstream. --- .../vcpkg/overlay-ports/curl/portfile.cmake | 1 + .../CMake/vcpkg/overlay-ports/curl/vcpkg.json | 23 +++++++++++++++++-- .../RequestServer/ConnectionFromClient.cpp | 4 ++++ Services/RequestServer/ConnectionFromClient.h | 1 + vcpkg.json | 3 +++ 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Meta/CMake/vcpkg/overlay-ports/curl/portfile.cmake b/Meta/CMake/vcpkg/overlay-ports/curl/portfile.cmake index acace7742e9..145ccdc9234 100644 --- a/Meta/CMake/vcpkg/overlay-ports/curl/portfile.cmake +++ b/Meta/CMake/vcpkg/overlay-ports/curl/portfile.cmake @@ -14,6 +14,7 @@ vcpkg_from_github( vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS FEATURES http2 USE_NGHTTP2 + http3 USE_NGTCP2 wolfssl CURL_USE_WOLFSSL openssl CURL_USE_OPENSSL mbedtls CURL_USE_MBEDTLS diff --git a/Meta/CMake/vcpkg/overlay-ports/curl/vcpkg.json b/Meta/CMake/vcpkg/overlay-ports/curl/vcpkg.json index 5ba1727c370..0f463941cbc 100644 --- a/Meta/CMake/vcpkg/overlay-ports/curl/vcpkg.json +++ b/Meta/CMake/vcpkg/overlay-ports/curl/vcpkg.json @@ -65,12 +65,31 @@ "name": "curl", "default-features": false, "features": [ - "ssl" + "openssl" ] }, "nghttp2" ] }, + "http3": { + "description": "HTTP3 support", + "dependencies": [ + { + "name": "curl", + "default-features": false, + "features": [ + "openssl" + ] + }, + "nghttp3", + { + "name": "ngtcp2", + "features": [ + "openssl" + ] + } + ] + }, "httpsrr": { "description": "enable support for HTTPS RR" }, @@ -125,7 +144,7 @@ ] }, "non-http": { - "description": "Enables protocols beyond HTTP/HTTPS/HTTP2" + "description": "Enables protocols beyond HTTP/HTTPS/HTTP2/HTTP3" }, "openssl": { "description": "SSL support (OpenSSL)", diff --git a/Services/RequestServer/ConnectionFromClient.cpp b/Services/RequestServer/ConnectionFromClient.cpp index 838d8d3988b..730182af504 100644 --- a/Services/RequestServer/ConnectionFromClient.cpp +++ b/Services/RequestServer/ConnectionFromClient.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -315,6 +316,8 @@ ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr transpo { s_connections.set(client_id(), *this); + m_alt_svc_cache_path = ByteString::formatted("{}/Ladybird/alt-svc-cache.txt", Core::StandardPaths::user_data_directory()); + m_curl_multi = curl_multi_init(); auto set_option = [this](auto option, auto value) { @@ -488,6 +491,7 @@ void ConnectionFromClient::start_request(i32 request_id, ByteString method, URL: set_option(CURLOPT_PORT, url.port_or_default()); set_option(CURLOPT_CONNECTTIMEOUT, s_connect_timeout_seconds); set_option(CURLOPT_PIPEWAIT, 1L); + set_option(CURLOPT_ALTSVC, m_alt_svc_cache_path.characters()); bool did_set_body = false; diff --git a/Services/RequestServer/ConnectionFromClient.h b/Services/RequestServer/ConnectionFromClient.h index 87d2550d518..bd9a8cfd24a 100644 --- a/Services/RequestServer/ConnectionFromClient.h +++ b/Services/RequestServer/ConnectionFromClient.h @@ -70,6 +70,7 @@ private: HashMap> m_read_notifiers; HashMap> m_write_notifiers; NonnullRefPtr m_resolver; + ByteString m_alt_svc_cache_path; }; // FIXME: Find a good home for this diff --git a/vcpkg.json b/vcpkg.json index c2e30ad6c5e..e47384033ed 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -14,9 +14,12 @@ }, { "name": "curl", + "default-features": false, "features": [ "brotli", + "non-http", "http2", + "http3", "openssl", "websockets" ]