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
- 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