Pass a pointer to a null-terminated string to the *url* parameter. The string
must point to a correctly formatted "RFC 3986+" URL or be a NULL pointer. The
URL parser only understands and parses the subset of URLS that are
-"hierarchical" and therefore contain a :// separator - not the ones that are
+"hierarchical" and therefore contain a `://` separator - not the ones that are
normally specified with only a colon separator.
By default this API only parses URLs using schemes for protocols that are
When a full URL is set (parsed), the hostname component is stored URL decoded.
+It is considered fine to set a blank URL ("") as a redirect, but not as a
+normal URL. Therefore, setting a "" URL works fine if the handle already holds
+a URL, otherwise it triggers an error.
+
## CURLUPART_SCHEME
Scheme cannot be URL decoded on set. libcurl only accepts setting schemes up
CURLUcode uc;
char *oldurl;
- if(!nalloc)
- /* a blank URL is not a valid URL */
+ if(!nalloc) {
+ /* a blank URL is not a valid URL unless we already have a complete one
+ and this is a redirect */
+ if(!curl_url_get(u, CURLUPART_URL, &oldurl, flags)) {
+ /* success, meaning the "" is a fine relative URL, but nothing
+ changes */
+ free(oldurl);
+ return CURLUE_OK;
+ }
return CURLUE_MALFORMED_INPUT;
+ }
/* if the new thing is absolute or the old one is not (we could not get an
* absolute URL in 'oldurl'), then replace the existing with the new. */
/* !checksrc! disable SPACEBEFORECOMMA 1 */
static const struct setcase set_parts_list[] = {
+ {NULL, /* start fresh! */
+ "scheme=https,path=/,url=\"\",", /* incomplete url, redirect to "" */
+ "https://example.com/",
+ 0, 0, CURLUE_OK, CURLUE_MALFORMED_INPUT},
+ {NULL, /* start fresh! */
+ "scheme=https,host=example.com,path=/,url=\"\",", /* redirect to "" */
+ "https://example.com/",
+ 0, 0, CURLUE_OK, CURLUE_OK},
{"https://example.com/",
"path=one\ntwo,",
"https://example.com/one\ntwo",
}
static const struct redircase set_url_list[] = {
+ {"https://example.com",
+ "", /* blank redirect */
+ "https://example.com/",
+ 0, 0, CURLUE_OK },
{"http://firstplace.example.com/want/1314",
"//somewhere.example.com/reply/1314",
"http://somewhere.example.com/reply/1314",