CURLOPT_REDIR_PROTOCOLS(3)

πŸ’… CURLOPT_REDIR_PROTOCOLS πŸ’…

okay so this is a page from the libcurl manual (Library Functions Manual, bestie β€” that's the vibe) and we're talking about CURLOPT_REDIR_PROTOCOLS. Strap in. πŸŽ€

✨ NAME ✨

CURLOPT_REDIR_PROTOCOLS β€” the protocols libcurl is allowed to redirect to. like, which ones get the green light, y'know? 🚦

🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_REDIR_PROTOCOLS, long bitmask);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay first things first, and I need you to hear me on this: this option is deprecated. like, it's giving "still works but please move on." we strongly recommend using CURLOPT_REDIR_PROTOCOLS_STR(3) instead, because this one genuinely cannot control all the available protocols. not a skill issue exactly, but also lowkey a skill issue. 😭

So you pass a long that holds a bitmask of protocol bits. If you use it, this bitmask limits what protocols libcurl may use in a transfer that it follows to in a redirect β€” that only kicks in when CURLOPT_FOLLOWLOCATION(3) is enabled. Basically it lets you limit specific transfers so they're only allowed to use a subset of protocols when redirects happen. cute, controlled, contained. ✨

Important though: protocols that are denied by CURLOPT_PROTOCOLS(3) are not overridden by this option. no take-backs, no sneaking around it. πŸ™…β€β™€οΈ

By default libcurl allows HTTP, HTTPS, FTP and FTPS on redirect (since 7.65.2). And CURLPROTO_ALL enables all protocols on redirect β€” including the ones that are otherwise disabled for security. so like, be so serious when you use that one, okay? πŸ”₯

These are the available protocol defines, and yes I'm listing every single one because we don't skip:

CURLPROTO_DICT
CURLPROTO_FILE
CURLPROTO_FTP
CURLPROTO_FTPS
CURLPROTO_GOPHER
CURLPROTO_HTTP
CURLPROTO_HTTPS
CURLPROTO_IMAP
CURLPROTO_IMAPS
CURLPROTO_LDAP
CURLPROTO_LDAPS
CURLPROTO_POP3
CURLPROTO_POP3S
CURLPROTO_RTMP
CURLPROTO_RTMPE
CURLPROTO_RTMPS
CURLPROTO_RTMPT
CURLPROTO_RTMPTE
CURLPROTO_RTMPTS
CURLPROTO_RTSP
CURLPROTO_SCP
CURLPROTO_SFTP
CURLPROTO_SMB
CURLPROTO_SMBS
CURLPROTO_SMTP
CURLPROTO_SMTPS
CURLPROTO_TELNET
CURLPROTO_TFTP

like, the whole roster. the full friend group. πŸ’–

πŸŽ€ DEFAULT πŸŽ€

HTTP, HTTPS, FTP and FTPS (Added in 7.65.2).

Older versions defaulted to all protocols except FILE, SCP and β€” since 7.40.0 β€” SMB and SMBS. so, glow-up behavior over time, honestly. ⭐

🌈 PROTOCOLS 🌈

This functionality affects http only.

πŸ’œ EXAMPLE πŸ’œ

here's the whole thing, exactly as it should be, no notes:

int main(int argc, char **argv)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    /* pass in the URL from an external source */
    curl_easy_setopt(curl, CURLOPT_URL, argv[1]);

    /* only allow redirects to HTTP and HTTPS URLs */
    curl_easy_setopt(curl, CURLOPT_REDIR_PROTOCOLS,
                     CURLPROTO_HTTP | CURLPROTO_HTTPS);

    /* Perform the request */
    curl_easy_perform(curl);
  }
}

see how we're only letting it redirect to HTTP and HTTPS? that's the main character move right there. πŸ‘‘

🫢 HISTORY 🫢

CURLPROTO_* macros became long types in 8.16.0. prior to this version, a long cast was necessary when passed to curl_easy_setopt(3). so if you're on old code and something's being weird about types, iykyk. πŸ”

πŸ’€ DEPRECATED πŸ’€

Deprecated since 7.85.0. it's giving "still invited to the party but everyone knows." πŸ₯²

🌸 AVAILABILITY 🌸

Added in curl 7.19.4. vintage, honestly. πŸ“

✨ RETURN VALUE ✨

curl_easy_setopt(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). zero is the slay, non-zero is the "we need to talk." 😭

πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, bestie! this lil gem comes to you from the libcurl manual, dated 2026-10-12 β€” go forth and redirect responsibly. mwah. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from