1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_AUTOREFERER
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_EFFECTIVE_URL (3)
9  - CURLINFO_REDIRECT_URL (3)
10  - CURLINFO_REFERER (3)
11  - CURLOPT_FOLLOWLOCATION (3)
12  - CURLOPT_REFERER (3)
13Protocol:
14  - HTTP
15Added-in: 7.1
16---
17
18# NAME
19
20CURLOPT_AUTOREFERER - automatically update the referer header
21
22# SYNOPSIS
23
24~~~c
25#include <curl/curl.h>
26
27CURLcode curl_easy_setopt(CURL *handle, CURLOPT_AUTOREFERER, long autorefer);
28~~~
29
30# DESCRIPTION
31
32Pass a long parameter set to 1 to enable this. When enabled, libcurl
33automatically sets the Referer: header field in HTTP requests to the full URL
34when it follows a Location: redirect to a new destination.
35
36The automatic referer is set to the full previous URL even when redirects are
37done cross-origin or following redirects to insecure protocols. This is
38considered a minor privacy leak by some.
39
40With CURLINFO_REFERER(3), applications can extract the actually used
41referer header after the transfer.
42
43# DEFAULT
44
450, disabled
46
47# %PROTOCOLS%
48
49# EXAMPLE
50
51~~~c
52int main(void)
53{
54  CURL *curl = curl_easy_init();
55  if(curl) {
56    CURLcode res;
57    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
58
59    /* follow redirects */
60    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
61
62    /* set Referer: automatically when following redirects */
63    curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
64
65    res = curl_easy_perform(curl);
66
67    curl_easy_cleanup(curl);
68  }
69}
70~~~
71
72# %AVAILABILITY%
73
74# RETURN VALUE
75
76Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
77