xref: /aosp_15_r20/external/curl/docs/libcurl/opts/CURLOPT_AUTOREFERER.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker---
2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_AUTOREFERER
5*6236dae4SAndroid Build Coastguard WorkerSection: 3
6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl
7*6236dae4SAndroid Build Coastguard WorkerSee-also:
8*6236dae4SAndroid Build Coastguard Worker  - CURLINFO_EFFECTIVE_URL (3)
9*6236dae4SAndroid Build Coastguard Worker  - CURLINFO_REDIRECT_URL (3)
10*6236dae4SAndroid Build Coastguard Worker  - CURLINFO_REFERER (3)
11*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_FOLLOWLOCATION (3)
12*6236dae4SAndroid Build Coastguard Worker  - CURLOPT_REFERER (3)
13*6236dae4SAndroid Build Coastguard WorkerProtocol:
14*6236dae4SAndroid Build Coastguard Worker  - HTTP
15*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.1
16*6236dae4SAndroid Build Coastguard Worker---
17*6236dae4SAndroid Build Coastguard Worker
18*6236dae4SAndroid Build Coastguard Worker# NAME
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard WorkerCURLOPT_AUTOREFERER - automatically update the referer header
21*6236dae4SAndroid Build Coastguard Worker
22*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS
23*6236dae4SAndroid Build Coastguard Worker
24*6236dae4SAndroid Build Coastguard Worker~~~c
25*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h>
26*6236dae4SAndroid Build Coastguard Worker
27*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_AUTOREFERER, long autorefer);
28*6236dae4SAndroid Build Coastguard Worker~~~
29*6236dae4SAndroid Build Coastguard Worker
30*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION
31*6236dae4SAndroid Build Coastguard Worker
32*6236dae4SAndroid Build Coastguard WorkerPass a long parameter set to 1 to enable this. When enabled, libcurl
33*6236dae4SAndroid Build Coastguard Workerautomatically sets the Referer: header field in HTTP requests to the full URL
34*6236dae4SAndroid Build Coastguard Workerwhen it follows a Location: redirect to a new destination.
35*6236dae4SAndroid Build Coastguard Worker
36*6236dae4SAndroid Build Coastguard WorkerThe automatic referer is set to the full previous URL even when redirects are
37*6236dae4SAndroid Build Coastguard Workerdone cross-origin or following redirects to insecure protocols. This is
38*6236dae4SAndroid Build Coastguard Workerconsidered a minor privacy leak by some.
39*6236dae4SAndroid Build Coastguard Worker
40*6236dae4SAndroid Build Coastguard WorkerWith CURLINFO_REFERER(3), applications can extract the actually used
41*6236dae4SAndroid Build Coastguard Workerreferer header after the transfer.
42*6236dae4SAndroid Build Coastguard Worker
43*6236dae4SAndroid Build Coastguard Worker# DEFAULT
44*6236dae4SAndroid Build Coastguard Worker
45*6236dae4SAndroid Build Coastguard Worker0, disabled
46*6236dae4SAndroid Build Coastguard Worker
47*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS%
48*6236dae4SAndroid Build Coastguard Worker
49*6236dae4SAndroid Build Coastguard Worker# EXAMPLE
50*6236dae4SAndroid Build Coastguard Worker
51*6236dae4SAndroid Build Coastguard Worker~~~c
52*6236dae4SAndroid Build Coastguard Workerint main(void)
53*6236dae4SAndroid Build Coastguard Worker{
54*6236dae4SAndroid Build Coastguard Worker  CURL *curl = curl_easy_init();
55*6236dae4SAndroid Build Coastguard Worker  if(curl) {
56*6236dae4SAndroid Build Coastguard Worker    CURLcode res;
57*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
58*6236dae4SAndroid Build Coastguard Worker
59*6236dae4SAndroid Build Coastguard Worker    /* follow redirects */
60*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
61*6236dae4SAndroid Build Coastguard Worker
62*6236dae4SAndroid Build Coastguard Worker    /* set Referer: automatically when following redirects */
63*6236dae4SAndroid Build Coastguard Worker    curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
64*6236dae4SAndroid Build Coastguard Worker
65*6236dae4SAndroid Build Coastguard Worker    res = curl_easy_perform(curl);
66*6236dae4SAndroid Build Coastguard Worker
67*6236dae4SAndroid Build Coastguard Worker    curl_easy_cleanup(curl);
68*6236dae4SAndroid Build Coastguard Worker  }
69*6236dae4SAndroid Build Coastguard Worker}
70*6236dae4SAndroid Build Coastguard Worker~~~
71*6236dae4SAndroid Build Coastguard Worker
72*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY%
73*6236dae4SAndroid Build Coastguard Worker
74*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE
75*6236dae4SAndroid Build Coastguard Worker
76*6236dae4SAndroid Build Coastguard WorkerReturns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
77