curl/docs/libcurl/opts/CURLOPT_PROXY.3

132 lines
5.0 KiB
Groff
Raw Normal View History

.\" **************************************************************************
.\" * _ _ ____ _
.\" * Project ___| | | | _ \| |
.\" * / __| | | | |_) | |
.\" * | (__| |_| | _ <| |___
.\" * \___|\___/|_| \_\_____|
.\" *
.\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
.\" *
.\" * This software is licensed as described in the file COPYING, which
.\" * you should have received as part of this distribution. The terms
2020-11-04 21:02:01 +08:00
.\" * are also available at https://curl.se/docs/copyright.html.
.\" *
.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
.\" * copies of the Software, and permit persons to whom the Software is
.\" * furnished to do so, under the terms of the COPYING file.
.\" *
.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
.\" * KIND, either express or implied.
.\" *
.\" * SPDX-License-Identifier: curl
.\" *
.\" **************************************************************************
.\"
.TH CURLOPT_PROXY 3 "17 Jun 2014" libcurl libcurl
.SH NAME
CURLOPT_PROXY \- proxy to use
.SH SYNOPSIS
.nf
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PROXY, char *proxy);
.fi
.SH DESCRIPTION
Set the \fIproxy\fP to use for the upcoming request. The parameter should be a
char * to a null-terminated string holding the host name or dotted numerical
IP address. A numerical IPv6 address must be written within [brackets].
To specify 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 \fICURLOPT_PROXYPORT(3)\fP. If not specified, libcurl will default to
using port 1080 for proxies.
The proxy string may be prefixed with [scheme]:// to specify which kind of
proxy is used.
.RS
.IP http://
HTTP Proxy. Default when no scheme or proxy type is specified.
.IP https://
HTTPS Proxy. (Added in 7.52.0 for OpenSSL and GnuTLS Since 7.87.0, it
also works for BearSSL, mbedTLS, rustls, Schannel, Secure Transport and
wolfSSL.)
This will use HTTP/1 by default. Setting \fICURLOPT_PROXYTYPE(3)\fP to
\fBCURLPROXY_HTTPS2\fP allows libcurl to negotiate using HTTP/2 with proxy.
.IP socks4://
SOCKS4 Proxy.
.IP socks4a://
SOCKS4a Proxy. Proxy resolves URL hostname.
.IP socks5://
SOCKS5 Proxy.
.IP socks5h://
SOCKS5 Proxy. Proxy resolves URL hostname.
.RE
Without a scheme prefix, \fICURLOPT_PROXYTYPE(3)\fP can be used to specify
which kind of proxy the string identifies.
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
\fICURLOPT_QUOTE(3)\fP and similar FTP specifics that do not work unless you
tunnel through the HTTP proxy. Such tunneling is activated with
\fICURLOPT_HTTPPROXYTUNNEL(3)\fP.
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.
A proxy host string can also include protocol scheme (http://) and embedded
user + password.
Unix domain sockets are supported for socks proxies since 7.84.0. Set
localhost for the host part. e.g. socks5h://localhost/path/to/socket.sock
The application does not have to keep the string around after setting this
option.
KNOWN_BUGS: remove items not considered bugs any more - CURL_GLOBAL_SSL This option was changed in libcurl 7.57.0 and clearly it has not caused too many issues and a lot of time has passed. - Store TLS context per transfer instead of per connection This is a possible future optimization. One that is much less important and interesting since the added support for CA caching. - Microsoft telnet server This bug was filed in May 2007 against curl 7.16.1 and we have not received further reports. - active FTP over a SOCKS Actually, proxies in general is not working with active FTP mode. This is now added in proxy documentation. - DICT responses show the underlying protocol curl still does this, but since this is now an established behavior since forever we cannot change it easily and adding an option for it seems crazy as this protocol is not so little its not worth it. Let's just live with it. - Secure Transport disabling hostname validation also disables SNI This is an already documented restriction in Secure Transport. - CURLOPT_SEEKFUNCTION not called with CURLFORM_STREAM The curl_formadd() function is marked and documented as deprecated. No point in collecting bugs for it. It should not be used further. - STARTTRANSFER time is wrong for HTTP POSTs After close source code inspection I cannot see how this is true or that there is any special treatment for different HTTP methods. We also have not received many further reports on this, making me strongly suspect that this is no (longer an) issue. - multipart formposts file name encoding The once proposed RFC 5987-encoding is since RFC 7578 documented as MUST NOT be used. The since then implemented MIME API allows the user to set the name on their own and can thus provide it encoded as it wants. - DoH is not used for all name resolves when enabled It is questionable if users actually want to use DoH for interface and FTP port name resolving. This restriction is now documented and we advice users against using name resolving at all for these functions. Closes #10043
2022-12-06 20:00:35 +08:00
When a proxy is used, the active FTP mode as set with \fICUROPT_FTPPORT(3)\fP,
cannot be used.
.SH "Environment variables"
libcurl respects the proxy environment variables named \fBhttp_proxy\fP,
\fBftp_proxy\fP, \fBsftp_proxy\fP etc. If set, libcurl will use the specified
proxy for that URL scheme. So for a "FTP://" URL, the \fBftp_proxy\fP is
considered. \fBall_proxy\fP is used if no protocol specific proxy was set.
If \fBno_proxy\fP (or \fBNO_PROXY\fP) is set, it is the exact equivalent of
setting the \fICURLOPT_NOPROXY(3)\fP option.
The \fICURLOPT_PROXY(3)\fP and \fICURLOPT_NOPROXY(3)\fP options override
environment variables.
.SH DEFAULT
Default is NULL, meaning no proxy is used.
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!
.SH PROTOCOLS
All except file://. Note that some protocols do not work well over proxy.
.SH EXAMPLE
.nf
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/file.txt");
curl_easy_setopt(curl, CURLOPT_PROXY, "http://proxy:80");
curl_easy_perform(curl);
}
.fi
.SH 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.
.SH 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.
.SH "SEE ALSO"
.BR CURLOPT_PROXYPORT "(3), " CURLOPT_HTTPPROXYTUNNEL "(3), "
.BR CURLOPT_PROXYTYPE "(3)"