CURLOPT_DEFAULT_PROTOCOL(3)

πŸ’… CURLOPT_DEFAULT_PROTOCOL β€” bestie's guide to schemeless URLs ✨

okay so real talk: this is a page from the Library Functions Manual, and it's about CURLOPT_DEFAULT_PROTOCOL, which is literally the "what protocol do we assume when you forgot to type one" option. no cap, it's a lifesaver. 🫢


✨ NAME ✨

CURLOPT_DEFAULT_PROTOCOL β€” the default protocol to use when the URL is missing a scheme name πŸŽ€


🌸 SYNOPSIS 🌸

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEFAULT_PROTOCOL,
                          char *protocol);

πŸ¦‹ DESCRIPTION πŸ¦‹

so this option tells libcurl: "hey bestie, use protocol if the URL is missing a scheme name." that's it. that's the whole vibe. πŸ’–

Use one of these protocol (scheme) names:

dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps,
pop3, pop3s, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp

An unknown or unsupported protocol causes error CURLE_UNSUPPORTED_PROTOCOL when libcurl parses a URL without a scheme. 😭 Parsing happens when curl_easy_perform(3) or curl_multi_perform(3) is called. The protocol set supported by libcurl vary depending on how it was built. Use curl_version_info(3) if you need a list of protocol names supported by the build of libcurl that you are using. (yes, "vary" β€” that's the original wording, don't come for me πŸ™ˆ)

This option does not change the default proxy protocol (http). nope, that one's living its own life. πŸ’€

Without this option libcurl would make a guess based on the host, see CURLOPT_URL(3) for details. it's giving "trust the vibes" energy.

The application does not have to keep the string around after setting this option. 🧚 free your memory, queen.

Using this option multiple times makes the last set string override the previous ones. Set it to NULL to disable its use again. last one wins, periodt. πŸ‘‘


⭐ DEFAULT ⭐

NULL (make a guess based on the host) β€” lowkey just vibes.


🌈 PROTOCOLS 🌈

This functionality affects all supported protocols. every single one. no gatekeeping. πŸ’œ


πŸ”₯ EXAMPLE πŸ”₯

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    /* set a URL without a scheme */
    curl_easy_setopt(curl, CURLOPT_URL, "example.com");

    /* set the default protocol (scheme) for schemeless URLs */
    curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");

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

look at that. "example.com" with no scheme? iconic. it still slays because we set the default. πŸ”₯


πŸ’€ AVAILABILITY πŸ’€

Added in curl 7.45.0 β€” so if your curl is older than that, bestie, it's not gonna work. πŸŽ€


πŸ“ RETURN VALUE πŸ“

  • CURLE_OK if the option is supported. βœ… slay
  • CURLE_OUT_OF_MEMORY if there was insufficient heap space. 😭
  • CURLE_UNKNOWN_OPTION if the option is not supported. πŸ™ˆ

πŸ‘‘ SEE ALSO πŸ‘‘


⚠️ reminder: if you hand it a protocol that doesn't exist or your build doesn't support, you get CURLE_UNSUPPORTED_PROTOCOL β€” and it fires at parse time (curl_easy_perform(3) / curl_multi_perform(3)), not when you set the option. don't say i didn't warn you 🫢

and that's the whole page, bestie ✨ this one's from libcurl, dated 2026-10-12, and it's CURLOPT_DEFAULT_PROTOCOL(3) in the Library Functions Manual β€” go forth and never forget your scheme again πŸ’…πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from