CURLOPT_HTTPPROXYTUNNEL.md (2049B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_HTTPPROXYTUNNEL 5 Section: 3 6 Source: libcurl 7 Protocol: 8 - All 9 See-also: 10 - CURLOPT_PROXY (3) 11 - CURLOPT_PROXYPORT (3) 12 - CURLOPT_PROXYTYPE (3) 13 Added-in: 7.3 14 --- 15 16 # NAME 17 18 CURLOPT_HTTPPROXYTUNNEL - tunnel through HTTP proxy 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HTTPPROXYTUNNEL, long tunnel); 26 ~~~ 27 28 # DESCRIPTION 29 30 Set the **tunnel** parameter to 1L to make libcurl tunnel all operations 31 through the HTTP proxy (set with CURLOPT_PROXY(3)). There is a big 32 difference between using a proxy and to tunnel through it. 33 34 Tunneling means that an HTTP CONNECT request is sent to the proxy, asking it 35 to connect to a remote host on a specific port number and then the traffic is 36 just passed through the proxy. Proxies tend to white-list specific port numbers 37 it allows CONNECT requests to and often only port 80 and 443 are allowed. 38 39 To suppress proxy CONNECT response headers from user callbacks use 40 CURLOPT_SUPPRESS_CONNECT_HEADERS(3). 41 42 HTTP proxies can generally only speak HTTP (for obvious reasons), which makes 43 libcurl convert non-HTTP requests to HTTP when using an HTTP proxy without 44 this tunnel option set. For example, asking for an FTP URL and specifying an 45 HTTP proxy makes libcurl send an FTP URL in an HTTP GET request to the 46 proxy. By instead tunneling through the proxy, you avoid that conversion (that 47 rarely works through the proxy anyway). 48 49 # DEFAULT 50 51 0 52 53 # %PROTOCOLS% 54 55 # EXAMPLE 56 57 ~~~c 58 int main(void) 59 { 60 CURL *curl = curl_easy_init(); 61 if(curl) { 62 curl_easy_setopt(curl, CURLOPT_URL, "ftp://example.com/file.txt"); 63 curl_easy_setopt(curl, CURLOPT_PROXY, "http://127.0.0.1:80"); 64 curl_easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L); 65 curl_easy_perform(curl); 66 } 67 } 68 ~~~ 69 70 # %AVAILABILITY% 71 72 # RETURN VALUE 73 74 curl_easy_setopt(3) returns a CURLcode indicating success or error. 75 76 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 77 libcurl-errors(3).