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
15---
16
17# NAME
18
19CURLOPT_AUTOREFERER - automatically update the referer header
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLcode curl_easy_setopt(CURL *handle, CURLOPT_AUTOREFERER, long autorefer);
27~~~
28
29# DESCRIPTION
30
31Pass a long parameter set to 1 to enable this. When enabled, libcurl
32automatically sets the Referer: header field in HTTP requests to the full URL
33when it follows a Location: redirect to a new destination.
34
35The automatic referer is set to the full previous URL even when redirects are
36done cross-origin or following redirects to insecure protocols. This is
37considered a minor privacy leak by some.
38
39With CURLINFO_REFERER(3), applications can extract the actually used
40referer header after the transfer.
41
42# DEFAULT
43
440, disabled
45
46# EXAMPLE
47
48~~~c
49int main(void)
50{
51  CURL *curl = curl_easy_init();
52  if(curl) {
53    CURLcode res;
54    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
55
56    /* follow redirects */
57    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
58
59    /* set Referer: automatically when following redirects */
60    curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
61
62    res = curl_easy_perform(curl);
63
64    curl_easy_cleanup(curl);
65  }
66}
67~~~
68
69# AVAILABILITY
70
71Along with HTTP
72
73# RETURN VALUE
74
75Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
76