GNURLOPT_PROXY(3)
β¨ NAME β¨
Okay so bestie, this whole page is GNURLOPT_PROXY(3) from the gnurl/curl manualβand it's literally all about CURLOPT_PROXY, which is the option that sets the proxy to use. No cap, this is your go-to when you need to route your request through a proxy. π
π SYNOPSIS π
You gotta include the header and call it like this:
#include <gnurl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PROXY, char *proxy);
That's the whole vibe. β¨
πΈ DESCRIPTION πΈ
So this sets the proxy for your upcoming request. The parameter should be a char * to a null-terminated string holding the host name or dotted numerical IP address. And listenβif you've got a numerical IPv6 address, it must be written within [brackets]. Don't forget the brackets, bestie! π
To specify the port number in this string, just append :[port] to the end of the host name. The proxy's port number can also optionally be specified with the separate option CURLOPT_PROXYPORT(3). And if you don't specify it? libcurl will default to using port 1080 for proxies. Periodt. π
The proxy string may be prefixed with [scheme]:// to specify which kind of proxy is used. Here are all the options, slay:
http://β HTTP Proxy. This is the default when no scheme or proxy type is specified.https://β HTTPS Proxy. (Added in 7.52.0 for OpenSSL, GnuTLS and NSS)socks4://β SOCKS4 Proxy.socks4a://β SOCKS4a Proxy. Proxy resolves URL hostname.socks5://β SOCKS5 Proxy.socks5h://β SOCKS5 Proxy. Proxy resolves URL hostname.
Without a scheme prefix, you can use CURLOPT_PROXYTYPE(3) to specify which kind of proxy the string identifies. So you're not stuck if you don't wanna use the scheme prefix. πββοΈ
Now, when you tell the library to use an HTTP proxy, libcurl will transparently convert operations to HTTP even if you specify an FTP URL etc. This may have an impact on what other features of the library you can use, such as CURLOPT_QUOTE(3) and similar FTP specifics that don't work unless you tunnel through the HTTP proxy. Such tunneling is activated with CURLOPT_HTTPPROXYTUNNEL(3). So watch out for thatβit's giving "surprise behaviour." π
Setting the proxy string to "" (an empty string) will explicitly disable the use of a proxy, even if there is an environment variable set for it. So if you wanna ghost the proxy entirely, that's how you do it. π»
A proxy host string can also include protocol scheme (http://) and embedded user + password. So you can be extra like that. π
And good news: the application does not have to keep the string around after setting this option. So you can free that string and go about your day. π¦
πΏ Environment variables πΏ
libcurl respects the proxy environment variables named http_proxy, ftp_proxy, sftp_proxy etc. If set, libcurl will use the specified proxy for that URL scheme. So for a "FTP://" URL, the ftp_proxy is considered. And all_proxy is used if no protocol specific proxy was set. So it's got your back with the fallback. π«Ά
If no_proxy (or NO_PROXY) is set, it is the exact equivalent of setting the CURLOPT_NOPROXY(3) option. So you can control that too. β¨
And just so you know: the CURLOPT_PROXY(3) and CURLOPT_NOPROXY(3) options override environment variables. So if you set these options, they win. Periodt. π―
π DEFAULT π
Default is NULL, meaning no proxy is used. So if you don't set anything, you're not using a proxy. Simple.
When you set a host name to use, do not assume that there's any particular single port number used widely for proxies. Specify it! So don't be lazyβtell it the port. π ββοΈ
π PROTOCOLS π
All except file://. Note that some protocols don't do very well over proxy. So like, just be aware. πββοΈ
π EXAMPLE π
Here's how you do it:
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/file.txt");
curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80");
curl_easy_perform(curl);
}
That's the whole vibe. π₯
β¨ AVAILABILITY β¨
- Since 7.14.1 the proxy environment variable names can include the protocol scheme.
- Since 7.21.7 the proxy string supports the socks protocols as "schemes".
- Since 7.50.2, unsupported schemes in proxy strings cause libcurl to return error.
So it's been evolving, bestie. π
π RETURN VALUE π
Returns CURLE_OK if proxies are supported, CURLE_UNKNOWN_OPTION if not, or CURLE_OUT_OF_MEMORY if there was insufficient heap space. So you know what to expect. π
π SEE ALSO π
You might also wanna check out:
These are the related pages, iykyk. π«Ά
That's it, bestie! This page was brought to you by libcurl 7.37.0, dated 17 Jun 2014. And remember, it's GNURLOPT_PROXY(3)βso you know where to find it. Stay slay! πβ¨π
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms