xref: /curl/docs/libcurl/curl_easy_duphandle.md (revision e3fe0200)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_easy_duphandle
5Section: 3
6Source: libcurl
7See-also:
8  - curl_easy_cleanup (3)
9  - curl_easy_init (3)
10  - curl_easy_reset (3)
11  - curl_global_init (3)
12Protocol:
13  - All
14---
15
16# NAME
17
18curl_easy_duphandle - Clone a libcurl session handle
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25CURL *curl_easy_duphandle(CURL *handle);
26~~~
27
28# DESCRIPTION
29
30This function returns a new curl handle, a duplicate, using all the options
31previously set in the input curl *handle*. Both handles can subsequently be
32used independently and they must both be freed with curl_easy_cleanup(3).
33
34Any options that the input handle has been told to point to (as opposed to
35copy) with previous calls to curl_easy_setopt(3), are pointed to by the new
36handle as well. You must therefore make sure to keep the data around until
37both handles have been cleaned up.
38
39The new handle does **not** inherit any state information, no connections, no
40SSL sessions and no cookies. It also does not inherit any share object states
41or options (created as if CURLOPT_SHARE(3) was set to NULL).
42
43If the source handle has HSTS or alt-svc enabled, the duplicate gets data read
44data from the main filename to populate the cache.
45
46In multi-threaded programs, this function must be called in a synchronous way,
47the input handle may not be in use when cloned.
48
49# EXAMPLE
50
51~~~c
52int main(void)
53{
54  CURL *curl = curl_easy_init();
55  if(curl) {
56    CURLcode res;
57    CURL *nother;
58    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
59    nother = curl_easy_duphandle(curl);
60    res = curl_easy_perform(nother);
61    curl_easy_cleanup(nother);
62    curl_easy_cleanup(curl);
63  }
64}
65~~~
66
67# AVAILABILITY
68
69Added in 7.9
70
71# RETURN VALUE
72
73If this function returns NULL, something went wrong and no valid handle was
74returned.
75