mirror of
https://github.com/curl/curl.git
synced 2026-07-24 17:07:16 +03:00
CURLOPT_DEFAULT_PROTOCOL: added
- Add new option CURLOPT_DEFAULT_PROTOCOL to allow specifying a default protocol for schemeless URLs. - Add new tool option --proto-default to expose CURLOPT_DEFAULT_PROTOCOL. In the case of schemeless URLs libcurl will behave in this way: When the option is used libcurl will use the supplied default. When the option is not used, libcurl will follow its usual plan of guessing from the hostname and falling back to 'http'.
This commit is contained in:
parent
22cb631198
commit
9756d1da76
21 changed files with 287 additions and 36 deletions
47
lib/url.c
47
lib/url.c
|
|
@ -2441,6 +2441,12 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
|||
data->set.redir_protocols = va_arg(param, long);
|
||||
break;
|
||||
|
||||
case CURLOPT_DEFAULT_PROTOCOL:
|
||||
/* Set the protocol to use when the URL doesn't include any protocol */
|
||||
result = setstropt(&data->set.str[STRING_DEFAULT_PROTOCOL],
|
||||
va_arg(param, char *));
|
||||
break;
|
||||
|
||||
case CURLOPT_MAIL_FROM:
|
||||
/* Set the SMTP mail originator */
|
||||
result = setstropt(&data->set.str[STRING_MAIL_FROM],
|
||||
|
|
@ -4028,27 +4034,30 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
|
|||
}
|
||||
|
||||
/*
|
||||
* Since there was no protocol part specified, we guess what protocol it
|
||||
* is based on the first letters of the server name.
|
||||
* Since there was no protocol part specified in the URL use the
|
||||
* user-specified default protocol. If we weren't given a default make a
|
||||
* guess by matching some protocols against the host's outermost
|
||||
* sub-domain name. Finally if there was no match use HTTP.
|
||||
*/
|
||||
|
||||
/* Note: if you add a new protocol, please update the list in
|
||||
* lib/version.c too! */
|
||||
|
||||
if(checkprefix("FTP.", conn->host.name))
|
||||
protop = "ftp";
|
||||
else if(checkprefix("DICT.", conn->host.name))
|
||||
protop = "DICT";
|
||||
else if(checkprefix("LDAP.", conn->host.name))
|
||||
protop = "LDAP";
|
||||
else if(checkprefix("IMAP.", conn->host.name))
|
||||
protop = "IMAP";
|
||||
else if(checkprefix("SMTP.", conn->host.name))
|
||||
protop = "smtp";
|
||||
else if(checkprefix("POP3.", conn->host.name))
|
||||
protop = "pop3";
|
||||
else {
|
||||
protop = "http";
|
||||
protop = data->set.str[STRING_DEFAULT_PROTOCOL];
|
||||
if(!protop) {
|
||||
/* Note: if you add a new protocol, please update the list in
|
||||
* lib/version.c too! */
|
||||
if(checkprefix("FTP.", conn->host.name))
|
||||
protop = "ftp";
|
||||
else if(checkprefix("DICT.", conn->host.name))
|
||||
protop = "DICT";
|
||||
else if(checkprefix("LDAP.", conn->host.name))
|
||||
protop = "LDAP";
|
||||
else if(checkprefix("IMAP.", conn->host.name))
|
||||
protop = "IMAP";
|
||||
else if(checkprefix("SMTP.", conn->host.name))
|
||||
protop = "smtp";
|
||||
else if(checkprefix("POP3.", conn->host.name))
|
||||
protop = "pop3";
|
||||
else
|
||||
protop = "http";
|
||||
}
|
||||
|
||||
*prot_missing = TRUE; /* not given in URL */
|
||||
|
|
|
|||
|
|
@ -1350,6 +1350,7 @@ enum dupstring {
|
|||
STRING_COOKIE, /* HTTP cookie string to send */
|
||||
STRING_COOKIEJAR, /* dump all cookies to this file */
|
||||
STRING_CUSTOMREQUEST, /* HTTP/FTP/RTSP request/method to use */
|
||||
STRING_DEFAULT_PROTOCOL, /* Protocol to use when the URL doesn't specify */
|
||||
STRING_DEVICE, /* local network interface/address to use */
|
||||
STRING_ENCODING, /* Accept-Encoding string */
|
||||
STRING_FTP_ACCOUNT, /* ftp account data */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue