1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_CONNECT_ONLY
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_HTTPPROXYTUNNEL (3)
9  - CURLOPT_VERBOSE (3)
10  - curl_easy_recv (3)
11  - curl_easy_send (3)
12Protocol:
13  - All
14Added-in: 7.15.2
15---
16
17# NAME
18
19CURLOPT_CONNECT_ONLY - stop when connected to target server
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CONNECT_ONLY, long only);
27~~~
28
29# DESCRIPTION
30
31Pass a long. If the parameter equals 1, it tells the library to perform all
32the required proxy authentication and connection setup, but no data transfer,
33and then return.
34
35The option can be used to simply test a connection to a server, but is more
36useful when used with the CURLINFO_ACTIVESOCKET(3) option to
37curl_easy_getinfo(3) as the library can set up the connection and then
38the application can obtain the most recently used socket for special data
39transfers.
40
41Since 7.86.0, this option can be set to '2' and if HTTP or WebSocket are used,
42libcurl performs the request and reads all response headers before handing
43over control to the application.
44
45Transfers marked connect only do not reuse any existing connections and
46connections marked connect only are not allowed to get reused.
47
48If the connect only transfer is done using the multi interface, the particular
49easy handle must remain added to the multi handle for as long as the
50application wants to use it. Once it has been removed with
51curl_multi_remove_handle(3), curl_easy_send(3) and
52curl_easy_recv(3) do not function.
53
54# DEFAULT
55
560
57
58# %PROTOCOLS%
59
60# EXAMPLE
61
62~~~c
63int main(void)
64{
65  CURL *curl = curl_easy_init();
66  if(curl) {
67    CURLcode ret;
68    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
69    curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
70    ret = curl_easy_perform(curl);
71    if(ret == CURLE_OK) {
72      /* only connected */
73    }
74  }
75}
76~~~
77
78# HISTORY
79
80WS and WSS support added in 7.86.0.
81
82# %AVAILABILITY%
83
84# RETURN VALUE
85
86Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
87