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 πŸ‘‘


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