diff --git a/docs/cmdline-opts/proto-default.md b/docs/cmdline-opts/proto-default.md
index 209e5cdc83..903fac73a5 100644
--- a/docs/cmdline-opts/proto-default.md
+++ b/docs/cmdline-opts/proto-default.md
@@ -16,7 +16,8 @@ Example:
# `--proto-default`
-Use *protocol* for any provided URL missing a scheme.
+Use *protocol* for any provided URL missing a scheme. The case-insensitive
+name should be given without any `://` suffix.
An unknown or unsupported protocol causes error *CURLE_UNSUPPORTED_PROTOCOL*.
@@ -24,3 +25,6 @@ This option does not change the default proxy protocol (http).
Without this option set, curl guesses protocol based on the hostname, see
--url for details.
+
+The default protocol cannot be set to `ipfs` or `ipns`. Those schemes need to
+be used explicitly in the URL.
diff --git a/src/config2setopts.c b/src/config2setopts.c
index 06c5dc6bb9..8933668a2c 100644
--- a/src/config2setopts.c
+++ b/src/config2setopts.c
@@ -147,29 +147,40 @@ static CURLcode url_proto_and_rewrite(char **url,
curl_url_set(uh, CURLUPART_URL, *url,
CURLU_GUESS_SCHEME | CURLU_NON_SUPPORT_SCHEME);
if(!uc) {
- uc = curl_url_get(uh, CURLUPART_SCHEME, &schemep, CURLU_DEFAULT_SCHEME);
- if(!uc) {
-#ifdef CURL_DISABLE_IPFS
- (void)config;
-#else
- if(curl_strequal(schemep, proto_ipfs) ||
- curl_strequal(schemep, proto_ipns)) {
- result = ipfs_url_rewrite(uh, schemep, url, config);
- /* short-circuit proto_token, we know it is ipfs or ipns */
- if(curl_strequal(schemep, proto_ipfs))
- proto = proto_ipfs;
- else if(curl_strequal(schemep, proto_ipns))
- proto = proto_ipns;
- if(result)
- config->synthetic_error = TRUE;
+ if(config->proto_default) {
+ /* when a default proto is requested, do not guess */
+ uc = curl_url_get(uh, CURLUPART_SCHEME, &schemep,
+ CURLU_NO_GUESS_SCHEME);
+ if(uc == CURLUE_NO_SCHEME) {
+ /* use the default */
+ proto = proto_token(config->proto_default);
+ if(proto)
+ uc = CURLUE_OK;
}
- else
-#endif /* !CURL_DISABLE_IPFS */
- proto = proto_token(schemep);
- curl_free(schemep);
}
- else if(uc == CURLUE_OUT_OF_MEMORY)
+ else {
+ uc = curl_url_get(uh, CURLUPART_SCHEME, &schemep,
+ CURLU_DEFAULT_SCHEME);
+ }
+ if(schemep)
+ proto = proto_token(schemep);
+#ifndef CURL_DISABLE_IPFS
+ if(!uc &&
+ (curl_strequal(schemep, proto_ipfs) ||
+ curl_strequal(schemep, proto_ipns))) {
+ result = ipfs_url_rewrite(uh, schemep, url, config);
+ /* short-circuit proto_token, we know it is ipfs or ipns */
+ if(curl_strequal(schemep, proto_ipfs))
+ proto = proto_ipfs;
+ else if(curl_strequal(schemep, proto_ipns))
+ proto = proto_ipns;
+ if(result)
+ config->synthetic_error = TRUE;
+ }
+#endif /* !CURL_DISABLE_IPFS */
+ if(uc == CURLUE_OUT_OF_MEMORY)
result = CURLE_OUT_OF_MEMORY;
+ curl_free(schemep);
}
else if(uc == CURLUE_OUT_OF_MEMORY)
result = CURLE_OUT_OF_MEMORY;
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index 5e5395b126..0a52bcc7f9 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -225,7 +225,7 @@ test1685 test1686 \
\
test1700 test1701 test1702 test1703 test1704 test1705 test1706 test1707 \
test1708 test1709 test1710 test1711 test1712 test1713 test1714 test1715 \
-test1720 test1721 test1722 test1723 \
+test1720 test1721 test1722 test1723 test1724 test1725 \
\
test1800 test1801 test1802 test1847 test1848 test1849 test1850 test1851 \
\
@@ -245,7 +245,7 @@ test2008 test2009 test2010 test2011 test2012 test2013 test2014 test2015 \
\
test2023 \
test2024 test2025 test2026 test2027 test2028 test2029 test2030 test2031 \
-test2032 test2033 test2034 test2035 test2037 test2038 test2039 \
+test2032 test2033 test2034 test2035 test2036 test2037 test2038 test2039 \
test2040 test2041 test2042 test2043 test2044 test2045 test2046 test2047 \
test2048 test2049 test2050 test2051 test2052 test2053 test2054 test2055 \
test2056 test2057 test2058 test2059 test2060 test2061 test2062 test2063 \
diff --git a/tests/data/test1724 b/tests/data/test1724
new file mode 100644
index 0000000000..3cd328e39c
--- /dev/null
+++ b/tests/data/test1724
@@ -0,0 +1,53 @@
+
+
+
+
+IPFS
+
+
+
+# Server-side
+
+
+HTTP/1.1 200 OK
+Date: Tue, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
+ETag: "21025-dc7-39462498"
+Accept-Ranges: bytes
+Content-Length: 21
+Connection: close
+Content-Type: text/plain
+Funny-head: yesyes
+
+Hello curl from IPFS
+
+
+
+# Client-side
+
+
+ipfs
+
+
+http
+
+
+IPFS with --proto-default HTTP
+
+
+--ipfs-gateway http://%HOSTIP:%HTTPPORT ipfs://bafybeidecnvkrygux6uoukouzps5ofkeevoqland7kopseiod6pzqvjg7u --proto-default http
+
+
+
+# Verify data after the test has been "shot"
+
+
+GET /ipfs/bafybeidecnvkrygux6uoukouzps5ofkeevoqland7kopseiod6pzqvjg7u HTTP/1.1
+Host: %HOSTIP:%HTTPPORT
+User-Agent: curl/%VERSION
+Accept: */*
+
+
+
+
diff --git a/tests/data/test1725 b/tests/data/test1725
new file mode 100644
index 0000000000..2a882c791d
--- /dev/null
+++ b/tests/data/test1725
@@ -0,0 +1,29 @@
+
+
+
+
+SCP
+server key check
+
+
+
+# Client-side
+
+
+scp
+
+
+SCP incorrect host key with --proto-default SCP
+
+
+--hostpubmd5 00000000000000000000000000000000 --key %LOGDIR/server/curl_client_key --pubkey %LOGDIR/server/curl_client_key.pub -u %USER: %HOSTIP:%SSHPORT%SCP_PWD/%LOGDIR/irrelevant-file --insecure --proto-default SCP
+
+
+
+# Verify data after the test has been "shot"
+
+
+60
+
+
+
diff --git a/tests/data/test2036 b/tests/data/test2036
new file mode 100644
index 0000000000..b017a71abc
--- /dev/null
+++ b/tests/data/test2036
@@ -0,0 +1,26 @@
+
+
+
+
+--proto-default
+
+
+
+# Client-side
+
+
+Attempt to set a default protocol with :// suffix
+
+
+--proto-default https://
+
+
+
+# Verify data after the test has been "shot"
+
+# CURLE_UNSUPPORTED_PROTOCOL is error code 1
+
+1
+
+
+