1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_DEFAULT_PROTOCOL
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_PROTOCOL (3)
9  - CURLINFO_SCHEME (3)
10  - CURLOPT_URL (3)
11Protocol:
12  - All
13Added-in: 7.45.0
14---
15
16# NAME
17
18CURLOPT_DEFAULT_PROTOCOL - default protocol to use if the URL is missing a
19scheme name
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEFAULT_PROTOCOL,
27                          char *protocol);
28~~~
29
30# DESCRIPTION
31
32This option tells libcurl to use *protocol* if the URL is missing a scheme
33name.
34
35Use one of these protocol (scheme) names:
36
37dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3,
38pop3s, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
39
40An unknown or unsupported protocol causes error *CURLE_UNSUPPORTED_PROTOCOL*
41when libcurl parses a URL without a scheme. Parsing happens when
42curl_easy_perform(3) or curl_multi_perform(3) is called. The protocol set
43supported by libcurl vary depending on how it was built. Use
44curl_version_info(3) if you need a list of protocol names supported by the
45build of libcurl that you are using.
46
47This option does not change the default proxy protocol (http).
48
49Without this option libcurl would make a guess based on the host, see
50CURLOPT_URL(3) for details.
51
52The application does not have to keep the string around after setting this
53option.
54
55Using this option multiple times makes the last set string override the
56previous ones. Set it to NULL to disable its use again.
57
58# DEFAULT
59
60NULL (make a guess based on the host)
61
62# %PROTOCOLS%
63
64# EXAMPLE
65
66~~~c
67int main(void)
68{
69  CURL *curl = curl_easy_init();
70  if(curl) {
71    /* set a URL without a scheme */
72    curl_easy_setopt(curl, CURLOPT_URL, "example.com");
73
74    /* set the default protocol (scheme) for schemeless URLs */
75    curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
76
77    /* Perform the request */
78    curl_easy_perform(curl);
79  }
80}
81~~~
82
83# %AVAILABILITY%
84
85# RETURN VALUE
86
87CURLE_OK if the option is supported.
88
89CURLE_OUT_OF_MEMORY if there was insufficient heap space.
90
91CURLE_UNKNOWN_OPTION if the option is not supported.
92