From 90270054115e00a49e0fdfbed406ae23cceac198 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 19 Aug 2001 17:09:06 +0000 Subject: SM's fix for -G on URLs with host name only --- src/main.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index 948bfab0d..0e82748cc 100644 --- a/src/main.c +++ b/src/main.c @@ -314,10 +314,10 @@ static void help(void) " -f/--fail Fail silently (no output at all) on errors (H)\n" " -F/--form Specify HTTP POST data (H)\n" " -g/--globoff Disable URL sequences and ranges using {} and []\n" - " -G/--get HTTP GET(H)\n" - " -h/--help This help text\n" - " -H/--header Custom header to pass to server. (H)"); - puts(" -i/--include Include the HTTP-header in the output (H)\n" + " -G/--get Send the -d data with a HTTP GET (H)\n"); + puts(" -h/--help This help text\n" + " -H/--header Custom header to pass to server. (H)" + " -i/--include Include the HTTP-header in the output (H)\n" " -I/--head Fetch document info only (HTTP HEAD/FTP SIZE)\n" " --interface Specify the interface to be used\n" " --krb4 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); } 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. */ @@ -1864,7 +1872,14 @@ operate(struct Configurable *config, int argc, char *argv[]) helpf("out of memory\n"); 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 */ url = urlbuffer; /* use our new URL instead! */ } -- cgit v1.2.1