GNURLINFO_REDIRECT_URL(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

Hey bestie πŸ’– welcome to the GNURLINFO_REDIRECT_URL(3) page β€” it belongs to the curl_easy_getinfo options manual, and we're about to make redirect URLs make sense. No cap.

✨ NAME ✨

CURLINFO_REDIRECT_URL β€” get the URL a redirect would go to. Periodt.

πŸ¦‹ SYNOPSIS πŸ¦‹

First, the include and function sig, exactly as they live:

#include <gnurl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_REDIRECT_URL, char
       **urlp);

🌸 DESCRIPTION 🌸

Okay so here's the tea: you pass a pointer to a char pointer β€” that's the char **urlp situation β€” to receive the URL a redirect would take you to if you enabled CURLOPT_FOLLOWLOCATION(3).

This is highkey handy if you think using the built-in libcurl redirect logic isn't good enough for you, but you'd still prefer to avoid implementing all the magic of figuring out the new URL.

This URL is also set if the CURLOPT_MAXREDIRS(3) limit prevented a redirect to happen (since 7.54.1). πŸ’…

🌈 PROTOCOLS 🌈

HTTP(S) β€” that's the whole list, bestie. πŸ’…

πŸŽ€ EXAMPLE πŸŽ€

Here's the example code, untouched and iconic:

CURL *curl = curl_easy_init();
if(curl) {
  CURLcode res;
  curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
  res = curl_easy_perform(curl);
  if(res == CURLE_OK) {
    char *url = NULL;
    curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &url);
    if(url)
      printf("Redirect to: %s\n", url);
  }
  curl_easy_cleanup(curl);
}

⭐ AVAILABILITY ⭐

Added in 7.18.2 ✨

πŸ‘‘ RETURN VALUE πŸ‘‘

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. Simple as that, no cap.

πŸ’œ SEE ALSO πŸ’œ

Go peek at these too:


Mwah πŸ’‹ this iconic page comes from libcurl 7.44.0, dated 28 Aug 2015 β€” and yes, the page is GNURLINFO_REDIRECT_URL(3). Bye bestie 🫢

πŸ“¦ where this page comes from