Skip to content

Commit 1cc117b

Browse files
vicromsNeumann-ABillyONealThomas1664
authored
[vcpkg-tool] Replace curl command calls with libcurl (#1660)
* add and link libcurl * Replace curl executable with libcurl API calls * Fix FindLibCURL for builds wihthout network access * Remove winHttp * Restore progress function * Handle non-dl transfer progress * Remove unused WinHttp code * Format and regenerate messages * Fix exepected console output of end-to-end test for multiple authoritative URLs in Windows * Remove unused parameter * Remove unused parameters 2 * Format and regenerate messages * Fix curl info read loop * Fix warnings and remove unused messages * Update src/vcpkg/binarycaching.cpp Co-authored-by: Billy O'Neal <[email protected]> * Delete CurlRequestPrivateData (#2) * PR comments WIP * Format and regenerate messages * Fix download retry * More review comments * Handle response code from file:// downloads/ * Update end-to-end test expected output * Fix download progress * Add curl license and notices * Fix call to upload metrics * Fix expected output comparison with newer versions of libcurl * Fix expected output comparison with newer versions of libcurl * Apply suggestions from code review Co-authored-by: Billy O'Neal <[email protected]> Co-authored-by: Thomas1664 <[email protected]> * More PR comments * Disable curl examples and fix out-of-bounds access in retry loop --------- Co-authored-by: Alexander Neumann <[email protected]> Co-authored-by: Billy O'Neal <[email protected]> Co-authored-by: Thomas1664 <[email protected]>
1 parent 602278b commit 1cc117b

File tree

24 files changed

+900
-1379
lines changed

24 files changed

+900
-1379
lines changed

.github/workflows/build.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ jobs:
3636
uses: github/codeql-action/init@v3
3737
with:
3838
languages: javascript-typescript, c-cpp
39+
- name: Install system libcurl
40+
if: matrix.preset == 'linux-arm64-ci' || matrix.preset == 'linux-ci'
41+
run: |
42+
sudo apt update
43+
sudo apt install -y libcurl4-openssl-dev
3944
- name: Configure and Build
4045
if: matrix.preset != 'windows-ci'
4146
run: |

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ set(TEST_SCRIPT_ASSET_CACHE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/test-script
195195

196196
find_package(fmt REQUIRED)
197197
find_package(CMakeRC REQUIRED)
198+
find_package(LibCURL REQUIRED)
198199

199200
# === Target: locale-resources ===
200201

@@ -229,6 +230,8 @@ target_compile_definitions(vcpkglib PUBLIC
229230
_FILE_OFFSET_BITS=64
230231
)
231232

233+
target_link_libraries(vcpkglib PUBLIC CURL::libcurl)
234+
232235
if(VCPKG_STANDALONE_BUNDLE_SHA)
233236
target_compile_definitions(vcpkglib PUBLIC
234237
"VCPKG_STANDALONE_BUNDLE_SHA=${VCPKG_STANDALONE_BUNDLE_SHA}"

NOTICE.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,35 @@ SOFTWARE.
7171
=========================================
7272
END OF CMakeRC NOTICES, INFORMATION, AND LICENSE
7373

74+
curl
75+
76+
%% curl NOTICES, INFORMATION, AND LICENSE BEGIN HERE
77+
=========================================
78+
COPYRIGHT AND PERMISSION NOTICE
79+
80+
Copyright (C) Daniel Stenberg, <[email protected]>, and many
81+
contributors, see the THANKS file.
82+
83+
All rights reserved.
84+
85+
Permission to use, copy, modify, and distribute this software for any purpose
86+
with or without fee is hereby granted, provided that the above copyright
87+
notice and this permission notice appear in all copies.
88+
89+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
90+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
91+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN
92+
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
93+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
94+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
95+
OR OTHER DEALINGS IN THE SOFTWARE.
96+
97+
Except as contained in this notice, the name of a copyright holder shall not
98+
be used in advertising or otherwise to promote the sale, use or other dealings
99+
in this Software without prior written authorization of the copyright holder.
100+
=========================================
101+
END OF curl NOTICES, INFORMATION, AND LICENSE
102+
74103
The following third party software is incorporated into vcpkg-artifacts:
75104

76105
---------------------------------------------------------

azure-pipelines/end-to-end-tests-dir/asset-caching.ps1

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ Throw-IfNotFailed
5959
$expected = @(
6060
"A suitable version of cmake was not found \(required v[0-9.]+\)\.",
6161
"Trying to download cmake-[0-9.]+-[^.]+\.(zip|tar\.gz) using asset cache file://$assetCacheRegex/[0-9a-z]+",
62-
"error: curl: \(37\) Couldn't open file [^\n]+",
62+
"error: curl operation failed with error code 37 \((Couldn't|Could not) read a file:\/\/ file\)\.",
63+
"error: Not a transient network error, won't retry download from file://$assetCacheRegex/[0-9a-z]+"
6364
"error: there were no asset cache hits, and x-block-origin blocks trying the authoritative source https://github\.com/Kitware/CMake/releases/download/[^ ]+",
6465
"note: If you are using a proxy, please ensure your proxy settings are correct\.",
6566
"Possible causes are:",
@@ -111,7 +112,8 @@ if (-not ($actual -match $expected)) {
111112
Refresh-TestRoot
112113
$expected = @(
113114
"^Downloading https://localhost:1234/foobar\.html -> example3\.html",
114-
"error: curl: \(7\) Failed to connect to localhost port 1234( after \d+ ms)?: ((Could not|Couldn't) connect to server|Connection refused)",
115+
"error: curl operation failed with error code 7 \((Couldn't|Could not) connect to server\)\.",
116+
"error: Not a transient network error, won't retry download from https://localhost:1234/foobar\.html",
115117
"note: If you are using a proxy, please ensure your proxy settings are correct\.",
116118
"Possible causes are:",
117119
"1\. You are actually using an HTTP proxy, but setting HTTPS_PROXY variable to ``https//address:port``\.",
@@ -134,9 +136,11 @@ if (-not ($actual -match $expected)) {
134136
Refresh-TestRoot
135137
$expected = @(
136138
"^Downloading example3\.html, trying https://localhost:1234/foobar\.html",
139+
"error: curl operation failed with error code 7 \((Couldn't|Could not) connect to server\)\.",
140+
"error: Not a transient network error, won't retry download from https://localhost:1234/foobar\.html",
137141
"Trying https://localhost:1235/baz\.html",
138-
"error: curl: \(7\) Failed to connect to localhost port 1234( after \d+ ms)?: ((Could not|Couldn't) connect to server|Connection refused)",
139-
"error: curl: \(7\) Failed to connect to localhost port 1235( after \d+ ms)?: ((Could not|Couldn't) connect to server|Connection refused)",
142+
"error: curl operation failed with error code 7 \((Couldn't|Could not) connect to server\)\.",
143+
"error: Not a transient network error, won't retry download from https://localhost:1235/baz\.html",
140144
"note: If you are using a proxy, please ensure your proxy settings are correct\.",
141145
"Possible causes are:",
142146
"1\. You are actually using an HTTP proxy, but setting HTTPS_PROXY variable to ``https//address:port``\.",
@@ -188,42 +192,20 @@ if (-not ($actual -match $expected)) {
188192
}
189193

190194
# ... also with multiple authoritative URLs
191-
if ($IsWindows) {
192-
# WinHTTP
193-
Refresh-TestRoot
194-
$expected = @(
195-
"^Downloading example3\.html, trying https://nonexistent\.example\.com",
196-
"warning: Download https://nonexistent\.example\.com failed -- retrying after 1000ms",
197-
"warning: Download https://nonexistent\.example\.com failed -- retrying after 2000ms",
198-
"warning: Download https://nonexistent\.example\.com failed -- retrying after 4000ms",
199-
"Trying https://raw\.githubusercontent\.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE\.txt",
200-
"Successfully downloaded example3\.html",
201-
"$"
202-
) -join "`n"
203-
204-
$actual = Run-VcpkgAndCaptureOutput @commonArgs x-download "$TestDownloadsRoot/example3.html" --sha512 65077997890f66f6041bb3284bb7b88e27631411ccbc253201ca4e00c4bcc58c0d77edffda4975498797cc10772c7fd68fbeb13cc4ac493a3471a9d49e5b6f24 --url https://nonexistent.example.com --url https://raw.githubusercontent.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE.txt
205-
Throw-IfFailed
206-
if (-not ($actual -match $expected)) {
207-
throw "Failure: azurl (no), x-block-origin (no), asset-cache (n/a), download (succeed)"
208-
}
209-
}
210-
211-
# Force curl with --header
212195
Refresh-TestRoot
213196
$expected = @(
214197
"^Downloading example3\.html, trying https://nonexistent\.example\.com",
215-
"warning: (Problem : timeout\.|Transient problem: timeout) Will retry in 1 seconds?\. 3 retries left\.",
216-
"warning: (Problem : timeout\.|Transient problem: timeout) Will retry in \d+ seconds?\. 2 retries left\.",
217-
"warning: (Problem : timeout\.|Transient problem: timeout) Will retry in \d+ seconds?\. 1 (retries|retry) left\.",
218-
"Trying https://raw\.githubusercontent\.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE\.txt",
198+
"error: curl operation failed with error code 6 \((Couldn't|Could not) resolve (hostname|host name)\)\.",
199+
"error: Not a transient network error, won't retry download from https://nonexistent\.example\.com",
200+
"Trying https://raw\.githubusercontent\.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE\.txt"
219201
"Successfully downloaded example3\.html",
220202
"$"
221203
) -join "`n"
222204

223205
$actual = Run-VcpkgAndCaptureOutput @commonArgs x-download "$TestDownloadsRoot/example3.html" --sha512 65077997890f66f6041bb3284bb7b88e27631411ccbc253201ca4e00c4bcc58c0d77edffda4975498797cc10772c7fd68fbeb13cc4ac493a3471a9d49e5b6f24 --url https://nonexistent.example.com --url https://raw.githubusercontent.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE.txt --header "Cache-Control: no-cache"
224206
Throw-IfFailed
225207
if (-not ($actual -match $expected)) {
226-
throw "Failure: azurl (no), x-block-origin (no), asset-cache (n/a), download (succeed)"
208+
throw "Failure: azurl (no), x-block-origin (no), asset-cache (n/a), download (succeed), headers (cache-control)"
227209
}
228210

229211
# azurl (no), x-block-origin (yes), asset-cache (n/a), download (n/a)
@@ -247,8 +229,10 @@ Refresh-TestRoot
247229
$expected = @(
248230
"^Trying to download example3\.html using asset cache file://$assetCacheRegex/[0-9a-z]+",
249231
"Asset cache miss; trying authoritative source https://localhost:1234/foobar\.html",
250-
"error: curl: \(37\) Couldn't open file [^\n]+",
251-
"error: curl: \(7\) Failed to connect to localhost port 1234( after \d+ ms)?: ((Could not|Couldn't) connect to server|Connection refused)",
232+
"error: curl operation failed with error code 37 \((Couldn't|Could not) read a file:// file\)\.",
233+
"error: Not a transient network error, won't retry download from file://$assetCacheRegex/[0-9a-z]+",
234+
"error: curl operation failed with error code 7 \((Couldn't|Could not) connect to server\)\.",
235+
"error: Not a transient network error, won't retry download from https://localhost:1234/foobar\.html",
252236
"note: If you are using a proxy, please ensure your proxy settings are correct\.",
253237
"Possible causes are:",
254238
"1\. You are actually using an HTTP proxy, but setting HTTPS_PROXY variable to ``https//address:port``\.",
@@ -307,7 +291,11 @@ if (-not ($actual -match $expected)) {
307291
$expected = @(
308292
"^Trying to download example3\.html using asset cache file://$assetCacheRegex/[0-9a-z]+",
309293
"Asset cache miss; trying authoritative source https://raw\.githubusercontent\.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE\.txt",
310-
"error: curl: \(37\) Couldn't open file [^\n]+",
294+
"error: curl operation failed with error code 37 \((Couldn't|Could not) read a file:// file\)\.",
295+
"error: Not a transient network error, won't retry download from file://$assetCacheRegex/[0-9a-z]+",
296+
"[^\n]+example3\.html\.\d+\.part: error: download from https://raw\.githubusercontent\.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE\.txt had an unexpected hash",
297+
"note: Expected: d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73b",
298+
"note: Actual : 65077997890f66f6041bb3284bb7b88e27631411ccbc253201ca4e00c4bcc58c0d77edffda4975498797cc10772c7fd68fbeb13cc4ac493a3471a9d49e5b6f24",
311299
"note: If you are using a proxy, please ensure your proxy settings are correct\.",
312300
"Possible causes are:",
313301
"1\. You are actually using an HTTP proxy, but setting HTTPS_PROXY variable to ``https//address:port``\.",
@@ -317,9 +305,6 @@ $expected = @(
317305
"The value set by your proxy might be wrong, or have same ``https://`` prefix issue\.",
318306
"3\. Your proxy's remote server is out of service\.",
319307
"If you believe this is not a temporary download server failure and vcpkg needs to be changed to download this file from a different location, please submit an issue to https://github\.com/Microsoft/vcpkg/issues",
320-
"[^\n]+example3\.html\.\d+\.part: error: download from https://raw\.githubusercontent\.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE\.txt had an unexpected hash",
321-
"note: Expected: d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73b",
322-
"note: Actual : 65077997890f66f6041bb3284bb7b88e27631411ccbc253201ca4e00c4bcc58c0d77edffda4975498797cc10772c7fd68fbeb13cc4ac493a3471a9d49e5b6f24",
323308
"$"
324309
) -join "`n"
325310
$actual = Run-VcpkgAndCaptureOutput @commonArgs x-download "$TestDownloadsRoot/example3.html" --sha512 d06b93c883f8126a04589937a884032df031b05518eed9d433efb6447834df2596aebd500d69b8283e5702d988ed49655ae654c1683c7a4ae58bfa6b92f2b73b --url https://raw.githubusercontent.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE.txt "--x-asset-sources=x-azurl,file://$AssetCache,,readwrite"
@@ -369,7 +354,8 @@ if (-not ($actual -match $expected)) {
369354
Refresh-TestRoot
370355
$expected = @(
371356
"^Trying to download example3\.html using asset cache file://$assetCacheRegex/[0-9a-z]+",
372-
"error: curl: \(37\) Couldn't open file [^\n]+",
357+
"error: curl operation failed with error code 37 \((Couldn't|Could not) read a file:// file\)\.",
358+
"error: Not a transient network error, won't retry download from file://$assetCacheRegex/[0-9a-z]+",
373359
"error: there were no asset cache hits, and x-block-origin blocks trying the authoritative source https://raw\.githubusercontent\.com/microsoft/vcpkg-tool/1767aaee7b229c609f7ad5cf2f57b6a6cc309fb8/LICENSE\.txt",
374360
"note: or https://alternate\.example\.com",
375361
"note: If you are using a proxy, please ensure your proxy settings are correct\.",

cgmanifest.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@
3737
},
3838
"DevelopmentDependency": false,
3939
"DependencyRoots": []
40+
},
41+
{
42+
"Component": {
43+
"Type": "other",
44+
"other": {
45+
"name": "curl",
46+
"version": "8.17.0",
47+
"downloadUrl": "https://github.com/curl/curl/archive/refs/tags/curl-8_17_0.tar.gz",
48+
"hash": "88ab4b7aac12b26a6ad32fb0e1a9675288a45894438cb031102ef5d4ab6b33c2bc99cae0c70b71bdfa12eb49762827e2490555114c5eb4a6876b95e1f2a4eb74"
49+
}
50+
},
51+
"DevelopmentDependency": false,
52+
"DependencyRoots": []
4053
}
4154
]
4255
}

cmake/FindLibCURL.cmake

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
if (WIN32)
2+
option(VCPKG_DEPENDENCY_EXTERNAL_LIBCURL "Use an external version of the libcurl library" OFF)
3+
else()
4+
option(VCPKG_DEPENDENCY_EXTERNAL_LIBCURL "Use an external version of the libcurl library" ON)
5+
endif()
6+
7+
if(POLICY CMP0135)
8+
cmake_policy(SET CMP0135 NEW)
9+
endif()
10+
11+
if (VCPKG_DEPENDENCY_EXTERNAL_LIBCURL)
12+
find_package(CURL REQUIRED)
13+
return()
14+
endif()
15+
16+
# This option exists to allow the URI to be replaced with a Microsoft-internal URI in official
17+
# builds which have restricted internet access; see azure-pipelines/signing.yml
18+
# Note that the SHA512 is the same, so vcpkg-tool contributors need not be concerned that we built
19+
# with different content.
20+
if(NOT VCPKG_LIBCURL_URL)
21+
set(VCPKG_LIBCURL_URL "https://github.com/curl/curl/releases/download/curl-8_17_0/curl-8.17.0.tar.gz")
22+
endif()
23+
24+
include(FetchContent)
25+
FetchContent_Declare(
26+
LibCURL
27+
URL "${VCPKG_LIBCURL_URL}"
28+
URL_HASH "SHA512=88ab4b7aac12b26a6ad32fb0e1a9675288a45894438cb031102ef5d4ab6b33c2bc99cae0c70b71bdfa12eb49762827e2490555114c5eb4a6876b95e1f2a4eb74"
29+
)
30+
31+
if(NOT LibCURL_FIND_REQUIRED)
32+
message(FATAL_ERROR "LibCURL must be REQUIRED")
33+
endif()
34+
35+
# This is in function() so no need to backup the variables
36+
function(get_libcurl)
37+
set(BUILD_CURL_EXE OFF)
38+
set(BUILD_EXAMPLES OFF)
39+
set(BUILD_LIBCURL_DOCS OFF)
40+
set(BUILD_MISC_DOCS OFF)
41+
set(BUILD_SHARED_LIBS OFF)
42+
set(BUILD_TESTING OFF)
43+
set(CURL_ENABLE_EXPORT_TARGET OFF)
44+
set(CURL_USE_LIBSSH2 OFF)
45+
set(CURL_USE_LIBPSL OFF)
46+
if (WIN32)
47+
set(CURL_USE_SCHANNEL ON)
48+
endif()
49+
set(ENABLE_CURL_MANUAL OFF)
50+
set(ENABLE_UNICODE ON)
51+
set(PICKY_COMPILER OFF)
52+
set(USE_NGHTTP2 OFF)
53+
set(USE_LIBIDN2 OFF)
54+
set(CMAKE_DISABLE_FIND_PACKAGE_Perl ON)
55+
set(CMAKE_DISABLE_FIND_PACKAGE_ZLIB ON)
56+
set(CMAKE_DISABLE_FIND_PACKAGE_LibPSL ON)
57+
set(CMAKE_DISABLE_FIND_PACKAGE_LibSSH2 ON)
58+
set(CMAKE_DISABLE_FIND_PACKAGE_Brotli ON)
59+
set(CMAKE_DISABLE_FIND_PACKAGE_Zstd ON)
60+
set(CMAKE_DISABLE_FIND_PACKAGE_NGHTTP2 ON)
61+
set(CMAKE_DISABLE_FIND_PACKAGE_Libidn2 ON)
62+
if(MSVC)
63+
string(APPEND CMAKE_C_FLAGS " /wd6101")
64+
string(APPEND CMAKE_C_FLAGS " /wd6011")
65+
string(APPEND CMAKE_C_FLAGS " /wd6054")
66+
string(APPEND CMAKE_C_FLAGS " /wd6287")
67+
string(APPEND CMAKE_C_FLAGS " /wd6323")
68+
string(APPEND CMAKE_C_FLAGS " /wd6385")
69+
string(APPEND CMAKE_C_FLAGS " /wd6387")
70+
string(APPEND CMAKE_C_FLAGS " /wd28182")
71+
string(APPEND CMAKE_C_FLAGS " /wd28251")
72+
string(APPEND CMAKE_C_FLAGS " /wd28301")
73+
else()
74+
string(APPEND CMAKE_C_FLAGS " -Wno-error")
75+
endif()
76+
FetchContent_MakeAvailable(LibCURL)
77+
endfunction()
78+
79+
get_libcurl()
80+
81+
if(NOT TARGET CURL::libcurl)
82+
if(TARGET libcurl_static)
83+
add_library(CURL::libcurl ALIAS libcurl_static)
84+
target_compile_definitions(libcurl_static INTERFACE CURL_STATICLIB)
85+
elseif(TARGET libcurl)
86+
add_library(CURL::libcurl ALIAS libcurl)
87+
if(NOT BUILD_SHARED_LIBS)
88+
target_compile_definitions(libcurl INTERFACE CURL_STATICLIB)
89+
endif()
90+
else()
91+
message(FATAL_ERROR "After FetchContent_MakeAvailable(LibCURL) no suitable curl target (libcurl or libcurl_static) was found.")
92+
endif()
93+
endif()

include/vcpkg/base/contractual-constants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,4 +591,9 @@ namespace vcpkg
591591
inline constexpr StringLiteral StatusInstalled = "installed";
592592
inline constexpr StringLiteral StatusNotInstalled = "not-installed";
593593
inline constexpr StringLiteral StatusPurge = "purge";
594+
595+
// App Insights JSON response fields
596+
inline constexpr StringLiteral AppInsightsResponseItemsReceived = "itemsReceived";
597+
inline constexpr StringLiteral AppInsightsResponseItemsAccepted = "itemsAccepted";
598+
inline constexpr StringLiteral AppInsightsResponseErrors = "errors";
594599
}

include/vcpkg/base/curl.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#pragma once
2+
3+
#include <vcpkg/base/fwd/span.h>
4+
5+
#include <vcpkg/base/pragmas.h>
6+
7+
#include <vcpkg/commands.version.h>
8+
9+
VCPKG_MSVC_WARNING(push)
10+
// note: disable warning triggered by curl headers
11+
// ws2tcpip.h(968): warning C6101: Returning uninitialized memory '*Mtu': A successful path through the function does
12+
// not set the named _Out_ parameter.
13+
VCPKG_MSVC_WARNING(disable : 6101)
14+
#include <curl/curl.h>
15+
#include <curl/multi.h>
16+
VCPKG_MSVC_WARNING(pop)
17+
18+
namespace vcpkg
19+
{
20+
CURLcode get_curl_global_init_status() noexcept;
21+
22+
struct CurlEasyHandle
23+
{
24+
CurlEasyHandle();
25+
CurlEasyHandle(CurlEasyHandle&& other) noexcept;
26+
CurlEasyHandle& operator=(CurlEasyHandle&& other) noexcept;
27+
~CurlEasyHandle();
28+
29+
CURL* get();
30+
31+
private:
32+
CURL* m_ptr = nullptr;
33+
};
34+
35+
struct CurlMultiHandle
36+
{
37+
CurlMultiHandle();
38+
CurlMultiHandle(CurlMultiHandle&& other) noexcept;
39+
CurlMultiHandle& operator=(CurlMultiHandle&& other) noexcept;
40+
~CurlMultiHandle();
41+
42+
// Adds an easy handle to the multi handle but doesn't take ownership of it.
43+
// Makes sure that the easy handle is removed from the multi handle on cleanup.
44+
void add_easy_handle(CurlEasyHandle& easy_handle);
45+
46+
CURLM* get();
47+
48+
private:
49+
CURLM* m_ptr = nullptr;
50+
std::vector<CURL*> m_easy_handles;
51+
};
52+
53+
struct CurlHeaders
54+
{
55+
CurlHeaders() = default;
56+
CurlHeaders(View<std::string> headers);
57+
CurlHeaders(CurlHeaders&& other) noexcept;
58+
CurlHeaders& operator=(CurlHeaders&& other) noexcept;
59+
~CurlHeaders();
60+
61+
curl_slist* get() const;
62+
63+
private:
64+
curl_slist* m_headers = nullptr;
65+
};
66+
67+
constexpr char vcpkg_curl_user_agent[] =
68+
"vcpkg/" VCPKG_BASE_VERSION_AS_STRING "-" VCPKG_VERSION_AS_STRING " (curl)";
69+
}

0 commit comments

Comments
 (0)