CURLOPT_AUTOREFERER(3)
β¨ CURLOPT_AUTOREFERER β¨
Okay so bestie, we're diving into libcurl's CURLOPT_AUTOREFERER(3) β like, this little guy lives in the Library Functions Manual and it's genuinely about automatically updating the Referer header for you. No cap. Let's get into it π
πΈ NAME πΈ
CURLOPT_AUTOREFERER β automatically update the referer header π«
π¦ SYNOPSIS π¦
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_AUTOREFERER, long autorefer);
π DESCRIPTION π
So you pass a long parameter set to 1 to enable this, okay? And when it's enabled, libcurl is literally out here automatically setting the Referer: header field in HTTP requests to the full URL when it follows a Location: redirect to a new destination. Iconic behavior tbh π
β οΈ Okay so listen β the automatic referer is set to the full previous URL, even when redirects are done cross-origin, and even when following redirects to insecure protocols. Some people consider this a minor privacy leak π. Not me telling you what to do, just telling you what the page says. Privacy check, bestie!
And with CURLINFO_REFERER(3), applications can extract the referer header that actually got used, after the transfer. Which is super handy for peeking at what libcurl did π
β DEFAULT β
0, disabled β so it's off unless you turn it on, periodt π
π PROTOCOLS π
This functionality affects http only π«Ά
π§ EXAMPLE π§
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/foo.bin");
/* follow redirects */
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
/* set Referer: automatically when following redirects */
curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
Like, look at her go πβ¨
π₯ AVAILABILITY π₯
Added in curl 7.1 β she's been around a minute, ngl π
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK π β and a non-zero value means an error occurred, so go check out libcurl-errors(3) for the deets.
π SEE ALSO π
CURLINFO_EFFECTIVE_URL(3)CURLINFO_REDIRECT_URL(3)CURLINFO_REFERER(3)CURLOPT_FOLLOWLOCATION(3)CURLOPT_REFERER(3)
And that's the whole vibe, bestie π This libcurl page is dated 2026-10-12 and comes to you from the libcurl source, version-wise β mwah, go forth and refer correctly π
ππΈ
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms