CURLINFO_REDIRECT_COUNT(3)

πŸ’… CURLINFO_REDIRECT_COUNT(3) πŸ’…

okay so bestie, welcome to the CURLINFO_REDIRECT_COUNT(3) page β€” it's part of the Library Functions Manual, and it's literally about counting redirects. that's the whole vibe. let's get into it πŸŽ€


✨ NAME ✨

CURLINFO_REDIRECT_COUNT β€” the number of redirects, no cap 🌈


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_REDIRECT_COUNT,
                           long *countp);

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea: you pass a pointer to a long, and it receives the total number of redirections that were actually followed. that's it. that's the whole function. iconic, honestly πŸ’…

key word check πŸ” β€” actually followed. it's the count of redirects that genuinely got chased down, not the ones you merely dreamed about.

🧚 PROTOCOLS 🧚

this functionality affects all supported protocols β€” every single one, periodt πŸ‘‘


🌸 EXAMPLE 🌸

here's a whole little program, copy it exactly bestie, don't improvise:

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
    result = curl_easy_perform(curl);
    if(result == CURLE_OK) {
      long redirects;
      curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &redirects);
    }
    curl_easy_cleanup(curl);
  }
}

see what it's doing? sets the URL, turns on CURLOPT_FOLLOWLOCATION with 1L, performs, and if the result is CURLE_OK it grabs the redirect count into redirects. she's simple, she's clean, she ate πŸ“


⭐ AVAILABILITY ⭐

added in curl 7.9.7 β€” vintage but still slaying 🫢


πŸ’€ RETURN VALUE πŸ’€

curl_easy_getinfo(3) returns a CURLcode indicating success or error.

  • CURLE_OK (0) means everything was OK πŸŽ‰
  • non-zero means an error occurred β€” see libcurl-errors(3) for the whole saga 😭

πŸ”₯ SEE ALSO πŸ”₯

go read them, they're all besties with this one πŸ’œ


mwah πŸ’‹ that's the page! brought to you by libcurl, dated 2026-10-12, and it's literally called CURLINFO_REDIRECT_COUNT(3) in case you forgot already. go follow some redirects, you got this πŸ’–βœ¨

πŸ“¦ where this page comes from