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_OKif the option is supported. β slayCURLE_OUT_OF_MEMORYif there was insufficient heap space. πCURLE_UNKNOWN_OPTIONif 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 getCURLE_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
- 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