GNURLOPT_PROXY(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

✨ 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