unix-socket.d \
upload-file.d \
url.d \
+ url-query.d \
use-ascii.d \
user-agent.d \
user.d \
--- /dev/null
+c: Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
+SPDX-License-Identifier: curl
+Long: url-query
+Arg: <data>
+Help: Add a URL query part
+Protocols: all
+See-also: data-urlencode get
+Added: 7.87.0
+Category: http post upload
+Example: --url-query name=val $URL
+Example: --url-query =encodethis http://example.net/foo
+Example: --url-query name@file $URL
+Example: --url-query @fileonly $URL
+Example: --url-query "+name=%20foo" $URL
+Multi: append
+---
+This option adds a piece of data, usually a name + value pair, to the end of
+the URL query part. The syntax is identical to that used for --data-urlencode
+with one extension:
+
+If the argument starts with a '+' (plus), the rest of the string is provided
+as-is unencoded.
+
+The query part of a URL is the one following the question mark on the right
+end.
--unix-socket 7.40.0
--upload-file (-T) 4.0
--url 7.5
+--url-query 7.87.0
--use-ascii (-B) 5.0
--user (-u) 4.0
--user-agent (-A) 4.5.1
curl_slist_free_all(config->cookiefiles);
Curl_safefree(config->postfields);
+ Curl_safefree(config->query);
Curl_safefree(config->referer);
Curl_safefree(config->headerfile);
char *postfields;
curl_off_t postfieldsize;
char *referer;
+ char *query;
long timeout_ms;
long connecttimeout_ms;
long maxredirs;
#include "tool_paramhlp.h"
#include "tool_parsecfg.h"
#include "tool_main.h"
+#include "dynbuf.h"
#include "memdebug.h" /* keep this as LAST include */
{"db", "data-binary", ARG_STRING},
{"de", "data-urlencode", ARG_STRING},
{"df", "json", ARG_STRING},
+ {"dg", "url-query", ARG_STRING},
{"D", "dump-header", ARG_FILENAME},
{"e", "referer", ARG_STRING},
{"E", "cert", ARG_FILENAME},
size_t size = 0;
bool raw_mode = (subletter == 'r');
- if(subletter == 'e') { /* --data-urlencode */
+ if(subletter == 'g') { /* --url-query */
+#define MAX_QUERY_LEN 100000 /* larger is not likely to ever work */
+ char *query;
+ struct curlx_dynbuf dyn;
+ curlx_dyn_init(&dyn, MAX_QUERY_LEN);
+
+ if(*nextarg == '+') {
+ /* use without encoding */
+ query = strdup(&nextarg[1]);
+ if(!query)
+ return PARAM_NO_MEM;
+ }
+ else {
+ err = data_urlencode(global, nextarg, &query, &size);
+ if(err)
+ return err;
+ }
+
+ if(config->query) {
+ CURLcode result =
+ curlx_dyn_addf(&dyn, "%s&%s", config->query, query);
+ free(query);
+ if(result)
+ return PARAM_NO_MEM;
+ free(config->query);
+ config->query = curlx_dyn_ptr(&dyn);
+ }
+ else
+ config->query = query;
+
+ break; /* this is not a POST argument at all */
+ }
+ else if(subletter == 'e') { /* --data-urlencode */
err = data_urlencode(global, nextarg, &postdata, &size);
if(err)
return err;
{" --url <url>",
"URL to work with",
CURLHELP_CURL},
+ {" --url-query <data>",
+ "Add a URL query part",
+ CURLHELP_HTTP | CURLHELP_POST | CURLHELP_UPLOAD},
{"-B, --use-ascii",
"Use ASCII/text transfer",
CURLHELP_MISC},
global->isatty = orig_isatty;
}
- if(httpgetfields) {
+ if(httpgetfields || config->query) {
+ char *q = httpgetfields ? httpgetfields : config->query;
CURLU *uh = curl_url();
if(uh) {
char *updated;
if(curl_url_set(uh, CURLUPART_URL, per->this_url,
CURLU_GUESS_SCHEME) ||
- curl_url_set(uh, CURLUPART_QUERY, httpgetfields,
- CURLU_APPENDQUERY) ||
+ curl_url_set(uh, CURLUPART_QUERY, q, CURLU_APPENDQUERY) ||
curl_url_get(uh, CURLUPART_URL, &updated, CURLU_GUESS_SCHEME)) {
curl_url_cleanup(uh);
result = CURLE_OUT_OF_MEMORY;