xref: /curl/docs/libcurl/opts/CURLOPT_PRE_PROXY.md (revision e3fe0200)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_PRE_PROXY
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_HTTPPROXYTUNNEL (3)
9  - CURLOPT_PROXY (3)
10Protocol:
11  - All
12---
13
14# NAME
15
16CURLOPT_PRE_PROXY - pre-proxy host to use
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PRE_PROXY, char *preproxy);
24~~~
25
26# DESCRIPTION
27
28Set the *preproxy* to use for the upcoming request. The parameter should be a
29char * to a null-terminated string holding the hostname or dotted numerical IP
30address. A numerical IPv6 address must be written within [brackets].
31
32To specify port number in this string, append :[port] to the end of the host
33name. The proxy's port number may optionally be specified with the separate
34option CURLOPT_PROXYPORT(3). If not specified, libcurl defaults to using
35port 1080 for proxies.
36
37A pre proxy is a SOCKS proxy that curl connects to before it connects to the
38HTTP(S) proxy specified in the CURLOPT_PROXY(3) option. The pre proxy
39can only be a SOCKS proxy.
40
41The pre proxy string should be prefixed with [scheme]:// to specify which kind
42of socks is used. Use socks4://, socks4a://, socks5:// or socks5h:// (the last
43one to enable socks5 and asking the proxy to do the resolving, also known as
44*CURLPROXY_SOCKS5_HOSTNAME* type) to request the specific SOCKS version to
45be used. Otherwise SOCKS4 is used as default.
46
47Setting the pre proxy string to "" (an empty string) explicitly disables the
48use of a pre proxy.
49
50The application does not have to keep the string around after setting this
51option.
52
53# DEFAULT
54
55Default is NULL, meaning no pre proxy is used.
56
57When you set a hostname to use, do not assume that there is any particular
58single port number used widely for proxies. Specify it!
59
60# EXAMPLE
61
62~~~c
63int main(void)
64{
65  CURL *curl = curl_easy_init();
66  if(curl) {
67    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/file.txt");
68    curl_easy_setopt(curl, CURLOPT_PRE_PROXY, "socks4://socks-proxy:1080");
69    curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80");
70    curl_easy_perform(curl);
71  }
72}
73~~~
74
75# AVAILABILITY
76
77Added in 7.52.0
78
79# RETURN VALUE
80
81Returns CURLE_OK if proxies are supported, CURLE_UNKNOWN_OPTION if not, or
82CURLE_OUT_OF_MEMORY if there was insufficient heap space.
83