1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

SM's fix for -G on URLs with host name only

This commit is contained in:
Daniel Stenberg 2001-08-19 17:09:06 +00:00
parent 1d3542a38f
commit 9027005411

View File

@ -314,10 +314,10 @@ static void help(void)
" -f/--fail Fail silently (no output at all) on errors (H)\n" " -f/--fail Fail silently (no output at all) on errors (H)\n"
" -F/--form <name=content> Specify HTTP POST data (H)\n" " -F/--form <name=content> Specify HTTP POST data (H)\n"
" -g/--globoff Disable URL sequences and ranges using {} and []\n" " -g/--globoff Disable URL sequences and ranges using {} and []\n"
" -G/--get HTTP GET(H)\n" " -G/--get Send the -d data with a HTTP GET (H)\n");
" -h/--help This help text\n" puts(" -h/--help This help text\n"
" -H/--header <line> Custom header to pass to server. (H)"); " -H/--header <line> Custom header to pass to server. (H)"
puts(" -i/--include Include the HTTP-header in the output (H)\n" " -i/--include Include the HTTP-header in the output (H)\n"
" -I/--head Fetch document info only (HTTP HEAD/FTP SIZE)\n" " -I/--head Fetch document info only (HTTP HEAD/FTP SIZE)\n"
" --interface <interface> Specify the interface to be used\n" " --interface <interface> Specify the interface to be used\n"
" --krb4 <level> Enable krb4 with specified security level (F)\n" " --krb4 <level> Enable krb4 with specified security level (F)\n"
@ -1856,6 +1856,14 @@ operate(struct Configurable *config, int argc, char *argv[])
printf("%s%s\n", CURLseparator, url); printf("%s%s\n", CURLseparator, url);
} }
if (httpgetfields) { if (httpgetfields) {
/* Find out whether the url contains a file name */
char *pc =strstr(url, "://");
if(pc)
pc+=3;
else
pc=url;
pc = strrchr(pc, '/');
/* /*
* Then append ? followed by the get fields to the url. * Then append ? followed by the get fields to the url.
*/ */
@ -1864,7 +1872,14 @@ operate(struct Configurable *config, int argc, char *argv[])
helpf("out of memory\n"); helpf("out of memory\n");
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
sprintf(urlbuffer, "%s?%s", url, httpgetfields); /* Append / before the ? to create a well-formed url
if the url contains a hostname only
*/
if (pc)
sprintf(urlbuffer, "%s?%s", url, httpgetfields);
else
sprintf(urlbuffer, "%s/?%s", url, httpgetfields);
free(url); /* free previous URL */ free(url); /* free previous URL */
url = urlbuffer; /* use our new URL instead! */ url = urlbuffer; /* use our new URL instead! */
} }