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