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