CURLOPT_PROTOCOLS_STR(3)

okay bestie, welcome to the libcurl Library Functions Manual page for CURLOPT_PROTOCOLS_STR ✨ this is the one that decides which URL schemes your transfer is even allowed to touch, and honestly it's giving security-guard-at-the-club energy πŸ’…


🌸 NAME 🌸

CURLOPT_PROTOCOLS_STR β€” allowed protocols, aka the VIP list for your URL schemes 🫢


✨ SYNOPSIS ✨

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PROTOCOLS_STR, char *spec);

πŸ’– DESCRIPTION πŸ’–

So what you do is pass a pointer to a string, and that string holds a comma-separated list of protocol names (URL schemes) that are allowed in the transfer. The matching is case insensitive, ngl, so don't stress about caps πŸ”₯

This is lowkey iconic because it lets applications use a libcurl that was built to support a whole wide range of protocols, but still limit specific transfers so they're only allowed to use a subset of them. By default, libcurl accepts all protocols it was built with support for. See also CURLOPT_REDIR_PROTOCOLS_STR(3) πŸ‘‘

If you try to set a non-existing protocol, or if no matching protocol at all is set, it returns error. No cap, it will simply not let that slide πŸ™ˆ

These are the available protocols:

DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP,
LDAPS, MQTT, POP3, POP3S, RTMP, RTMPE, RTMPS, RTMPT, RTMPTE, RTMPTS,
RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP, WS, WSS

You can set "ALL" as a short-cut to enable all protocols. But bestie, be aware: by setting all, you may enable protocols that were not supported the day you write this, but are introduced in a future libcurl version 😭 the way that's a future-you problem fr fr

curl_version_info(3) can be used to get a list of all supported protocols in the current libcurl. And CURLINFO_SCHEME(3) is the recommended way to figure out the protocol used in a previous transfer 🌈

Using this option multiple times makes the last set string override the previous ones. Set it to NULL to restore to the internal default πŸ’œ


πŸŽ€ DEFAULT πŸŽ€

All protocols built-in β€” she's generous like that πŸ‘‘


πŸ¦‹ PROTOCOLS πŸ¦‹

This functionality affects all supported protocols πŸ’«


⭐ EXAMPLE ⭐

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 HTTP, TFTP and SFTP */
    curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, "http,tftp,sftp");

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

🌈 AVAILABILITY 🌈

Added in curl 7.85.0 β€” a whole era ✨


πŸ’€ RETURN VALUE πŸ’€

  • Returns CURLE_UNKNOWN_OPTION if the option is not implemented.
  • Returns CURLE_UNSUPPORTED_PROTOCOL if a listed protocol is not supported or disabled.
  • Returns CURLE_BAD_FUNCTION_ARGUMENT if no protocol is listed.
  • Else CURLE_OK β€” slay, we're good 🫢

πŸ‘‘ SEE ALSO πŸ‘‘

CURLINFO_SCHEME(3), CURLOPT_DEFAULT_PROTOCOL(3), CURLOPT_REDIR_PROTOCOLS_STR(3), CURLOPT_URL(3), curl_version_info(3)


and that's the page, bestie πŸŽ€ brought to you by libcurl, dated 2026-10-12, and yes the footer said CURLOPT_PROTOCOLS_STR(3) again because it loves a dramatic entrance πŸ’… see you in the next man page, mwah πŸ§šπŸ’–

πŸ“¦ where this page comes from