GNURLOPT_PROTOCOLS(3)

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

πŸ’… GNURLOPT_PROTOCOLS(3) πŸ’…

okay so this page lives in the curl_easy_setopt options family (gnurl edition, we're fancy), and it's all about which protocols your transfer is allowed to touch πŸŽ€


✨ NAME ✨

CURLOPT_PROTOCOLS β€” set allowed protocols, i.e. the VIP list at the door and your transfer is NOT getting in unless it's on it πŸ’…


🌸 SYNOPSIS 🌸

#include <gnurl/curl.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

so bestie, you pass a long that holds a bitmask made of CURLPROTO_* defines. If you use it, that bitmask limits what protocols libcurl may use in the transfer. the whole point? you can have a libcurl built to support a wide range of protocols but still limit specific transfers to only be allowed to use a subset of them. iconique, right? 🫢

by default libcurl will accept all protocols it supports (CURLPROTO_ALL). also go look at CURLOPT_REDIR_PROTOCOLS(3) while you're at it πŸ‘€

these are the available protocol defines, no cap, the whole list:

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

⭐ DEFAULT ⭐

all protocols built-in β€” like, everything the build came with, go wild 🌈


🧚 PROTOCOLS 🧚

All β€” every protocol, periodt.


πŸ”₯ EXAMPLE πŸ”₯

here's the vibe, literally copy-paste energy:

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,
                   CURLPROTO_HTTP | CURLPROTO_TFTP | CURLPROTO_SFTP);

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

see how those three get OR'd together with |? that's the bitmask slay πŸ’…


🌟 AVAILABILITY 🌟

added in 7.19.4 β€” vintage but still iconic πŸ‘‘


πŸ’– RETURN VALUE πŸ’–

returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. simple as that, no drama ✨


πŸ‘€ SEE ALSO πŸ‘€


ngl, this one's short but she matters β€” restricting protocols is like, the main character energy of safe transfers πŸ”₯

okay that's the whole page bestie, love that for us πŸ’œ β€” this gem is from libcurl 7.37.0, dated 19 Jun 2014, and it's the GNURLOPT_PROTOCOLS(3) manual page signing off πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from