CURLOPT_PRE_PROXY(3)
Hey bestie!! π Youβve landed on CURLOPT_PRE_PROXY(3) from the Library Functions Manual β the page all about the pre-proxy host to use. Grab a strawberry drink, because weβre getting into SOCKS-before-the-proxy territory. πβ¨
π NAME π
CURLOPT_PRE_PROXYβ pre-proxy host to use. Thatβs the whole name, no cap. π«Ά
β¨ SYNOPSIS β¨
Okay so first, include the curl header, then call curl_easy_setopt with this exact signature:
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PRE_PROXY, char *preproxy);
πΈ DESCRIPTION πΈ
Set the preproxy to use for the upcoming request. π
The parameter should be a char * to a null-terminated string holding the hostname or dotted numerical IP address. If youβre giving a numerical IPv6 address, it must be written within [brackets] β like, that part is not optional, bestie. π«Ά
To specify the port number in this string, append :[port] to the end of the host name. The proxyβs port number may optionally be specified with the separate option CURLOPT_PROXYPORT(3). If you donβt specify it, libcurl defaults to using port 1080 for proxies. π
A pre proxy is a SOCKS proxy that curl connects to before it connects to the HTTP(S) proxy specified in the CURLOPT_PROXY(3) option. The pre proxy can only be a SOCKS proxy β thatβs the vibe check it has to pass. β¨
The pre proxy string should be prefixed with [scheme]:// to specify which kind of socks is used. Use socks4://, socks4a://, socks5:// or socks5h:// to request the specific SOCKS version to be used. The last one, socks5h://, enables socks5 and asks the proxy to do the resolving β also known as CURLPROXY_SOCKS5_HOSTNAME type. Otherwise SOCKS4 is used as default. π
Setting the pre proxy string to "" (an empty string) explicitly disables the use of a pre proxy. π
β οΈ When you set a hostname to use, do not assume that there is any particular single port number used widely for proxies. Specify it. For real, donβt make it guess. π
The application does not have to keep the string around after setting this option. Set it and let it go, bestie. π¦
Using this option multiple times makes the last set string override the previous ones. Set it to NULL to disable its use again. π₯
π DEFAULT π
NULL β yep, thatβs the default, and itβs giving βno pre proxy unless you ask.β π
π¦ PROTOCOLS π¦
This functionality affects all supported protocols. All of them. No cap. π
β EXAMPLE β
Hereβs the example, with the calls and strings exactly as they should be:
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/file.txt");
curl_easy_setopt(curl, CURLOPT_PRE_PROXY, "socks4://socks-proxy:1080");
curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80");
curl_easy_perform(curl);
}
}
π§ AVAILABILITY π§
Added in curl 7.52.0. Itβs been iconic since then. π
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode indicating success or error. CURLE_OK (0) means everything was OK; non-zero means an error occurred β if that happens, see libcurl-errors(3). π
π SEE ALSO π
Signed off by libcurl Β· date 2026-10-12 Β· CURLOPT_PRE_PROXY(3), out! π
πβ¨
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms