curl_easy_duphandle(3)
π curl_easy_duphandle(3) β the libcurl glow-up
okay bestie, welcome to the libcurl corner of the manual, specifically the page about curl_easy_duphandle π β the function that literally clones your easy handle. it's giving copy-paste but make it C. β¨
β¨ NAME β¨
curl_easy_duphandle β clone an easy handle π«Ά
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURL *curl_easy_duphandle(CURL *handle);
π¦ DESCRIPTION π¦
okay so this function returns a new curl handle, a duplicate, using all the options previously set in the input curl handle. Both handles can subsequently be used independently and they must both be freed with curl_easy_cleanup(3). π₯ two for the price of one, no cap.
Any options that the input handle has been told to point to (as opposed to copy) with previous calls to curl_easy_setopt(3), are pointed to by the new handle as well. You must therefore make sure to keep the data around until both handles have been cleaned up. π like, both of them are holding hands with the same data, so don't yeet that data into the void, mmkay? π
The new handle does not inherit any state information, no connections, no SSL sessions and no cookies. It also does not inherit any share object states or options (created as if CURLOPT_SHARE(3) was set to NULL). π clean slate energy, honestly iconic.
If the source handle has HSTS or alt-svc enabled, the duplicate gets data read data from the main filename to populate the cache. β (yes, that's exactly what it says β "gets data read data from the main filename", we don't make the rules π§)
In multi-threaded programs, this function must be called in a synchronous way, the input handle may not be in use when cloned. π¨ like do not be cloning a handle that another thread is actively vibing with, that's a no from me.
π PROTOCOLS π
This functionality affects all supported protocols π β every single one, periodt.
π EXAMPLE π
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
CURL *nother;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
nother = curl_easy_duphandle(curl);
result = curl_easy_perform(nother);
curl_easy_cleanup(nother);
curl_easy_cleanup(curl);
}
}
look at that. one handle in, two handles out, both cleaned up like a responsible main character. π β¨
π AVAILABILITY π
Added in curl 7.9 β vintage but still slaying. π§π
β RETURN VALUE β
If this function returns NULL, something went wrong and no valid handle was returned. π yeah bestie, NULL means the clone did not survive the vibe check.
π₯ SEE ALSO π₯
ngl, if you're cloning handles you should also peep curl_easy_reset(3) β different vibe, same friend group. π«Ά
and that's the whole page, bestie! πΈ libcurl, 2026-10-12 β go forth and duplicate responsibly, mwah πππ§
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms