1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

SM's -G patch. There's some room for improvements still, as a command line

like: "curl -d moo=foo -G daniel.haxx.se" currently fails.
This commit is contained in:
Daniel Stenberg 2001-08-15 07:22:32 +00:00
parent 7d17713d62
commit f78de2d8c1

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 2000, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2001, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* In order to be useful for every potential user, curl and libcurl are * In order to be useful for every potential user, curl and libcurl are
* dual-licensed under the MPL and the MIT/X-derivate licenses. * dual-licensed under the MPL and the MIT/X-derivate licenses.
@ -231,12 +231,8 @@ long vms_cond[] = {
CURL_BADPWD, CURL_BADPWD,
CURL_MNYREDIR CURL_MNYREDIR
}; };
#endif #endif
extern void hugehelp(void); extern void hugehelp(void);
/* /*
@ -318,6 +314,7 @@ 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"
" -h/--help This help text\n" " -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" puts(" -i/--include Include the HTTP-header in the output (H)\n"
@ -414,6 +411,7 @@ struct Configurable {
bool progressmode; bool progressmode;
bool nobuffer; bool nobuffer;
bool globoff; bool globoff;
bool use_httpget;
char *writeout; /* %-styled format string to output */ char *writeout; /* %-styled format string to output */
@ -601,7 +599,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
{"a", "append", FALSE}, {"a", "append", FALSE},
{"A", "user-agent", TRUE}, {"A", "user-agent", TRUE},
{"b", "cookie", TRUE}, {"b", "cookie", TRUE},
{"B", "ftp-ascii", FALSE}, /* this long format is OBSOLETEE now! */ {"B", "ftp-ascii", FALSE}, /* this long format is OBSOLETE now! */
{"B", "use-ascii", FALSE}, {"B", "use-ascii", FALSE},
{"c", "continue", FALSE}, {"c", "continue", FALSE},
{"C", "continue-at", TRUE}, {"C", "continue-at", TRUE},
@ -615,6 +613,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
{"f", "fail", FALSE}, {"f", "fail", FALSE},
{"F", "form", TRUE}, {"F", "form", TRUE},
{"g", "globoff", FALSE}, {"g", "globoff", FALSE},
{"G", "get", FALSE},
{"h", "help", FALSE}, {"h", "help", FALSE},
{"H", "header", TRUE}, {"H", "header", TRUE},
{"i", "include", FALSE}, {"i", "include", FALSE},
@ -873,8 +872,8 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
config->postfields=postdata; config->postfields=postdata;
} }
if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) /* if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq))
return PARAM_BAD_USE; return PARAM_BAD_USE;*/
break; break;
case 'D': case 'D':
/* dump-header to given file name */ /* dump-header to given file name */
@ -943,6 +942,10 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
config->globoff ^= TRUE; config->globoff ^= TRUE;
break; break;
case 'G': /* HTTP GET */
config->use_httpget = TRUE;
break;
case 'h': /* h for help */ case 'h': /* h for help */
help(); help();
return PARAM_HELP_REQUESTED; return PARAM_HELP_REQUESTED;
@ -1542,6 +1545,8 @@ operate(struct Configurable *config, int argc, char *argv[])
bool allocuseragent=FALSE; bool allocuseragent=FALSE;
char *httpgetfields=NULL;
CURL *curl; CURL *curl;
int res; int res;
int i; int i;
@ -1555,6 +1560,7 @@ operate(struct Configurable *config, int argc, char *argv[])
config->showerror=TRUE; config->showerror=TRUE;
config->conf=CONF_DEFAULT; config->conf=CONF_DEFAULT;
config->use_httpget=FALSE;
if(argc>1 && if(argc>1 &&
(!strnequal("--", argv[1], 2) && (argv[1][0] == '-')) && (!strnequal("--", argv[1], 2) && (argv[1][0] == '-')) &&
@ -1642,6 +1648,23 @@ operate(struct Configurable *config, int argc, char *argv[])
else else
allocuseragent = TRUE; allocuseragent = TRUE;
if (config->postfields) {
if (config->use_httpget) {
/* Use the postfields data for a http get */
httpgetfields = strdup(config->postfields);
free(config->postfields);
config->postfields = NULL;
if(SetHTTPrequest(HTTPREQ_GET, &config->httpreq)) {
free(httpgetfields);
return PARAM_BAD_USE;
}
}
else {
if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq))
return PARAM_BAD_USE;
}
}
/* /*
* Get a curl handle to use for all forthcoming curl transfers. Cleanup * Get a curl handle to use for all forthcoming curl transfers. Cleanup
* when all transfers are done. This is supported with libcurl 7.7 and * when all transfers are done. This is supported with libcurl 7.7 and
@ -1832,6 +1855,19 @@ operate(struct Configurable *config, int argc, char *argv[])
if (separator) if (separator)
printf("%s%s\n", CURLseparator, url); printf("%s%s\n", CURLseparator, url);
} }
if (httpgetfields) {
/*
* Then append ? followed by the get fields to the url.
*/
urlbuffer=(char *)malloc(strlen(url) + strlen(httpgetfields) + 2);
if(!urlbuffer) {
helpf("out of memory\n");
return CURLE_OUT_OF_MEMORY;
}
sprintf(urlbuffer, "%s?%s", url, httpgetfields);
free(url); /* free previous URL */
url = urlbuffer; /* use our new URL instead! */
}
if(!config->errors) if(!config->errors)
config->errors = stderr; config->errors = stderr;
@ -1975,6 +2011,9 @@ operate(struct Configurable *config, int argc, char *argv[])
if(headerfilep) if(headerfilep)
fclose(headerfilep); fclose(headerfilep);
if (httpgetfields)
free(httpgetfields);
if(url) if(url)
free(url); free(url);