mirror of
https://github.com/curl/curl.git
synced 2024-12-27 06:59:43 +08:00
2e160c9c65
Add support for command line variables. Set variables with --variable name=content or --variable name@file (where "file" can be stdin if set to a single dash (-)). Variable content is expanded in option parameters using "{{name}}" (without the quotes) if the option name is prefixed with "--expand-". This gets the contents of the variable "name" inserted, or a blank if the name does not exist as a variable. Insert "{{" verbatim in the string by prefixing it with a backslash, like "\\{{". Import an environment variable with --variable %name. It makes curl exit with an error if the environment variable is not set. It can also rather get a default value if the variable does not exist, using =content or @file like shown above. Example: get the USER environment variable into the URL: --variable %USER --expand-url = "https://example.com/api/{{USER}}/method" When expanding variables, curl supports a set of functions that can make the variable contents more convenient to use. It can trim leading and trailing white space with "trim", output the contents as a JSON quoted string with "json", URL encode it with "url" and base 64 encode it with "b64". To apply functions to a variable expansion, add them colon separated to the right side of the variable. They are then performed in a left to right order. Example: get the contents of a file called $HOME/.secret into a variable called "fix". Make sure that the content is trimmed and percent-encoded sent as POST data: --variable %HOME=/home/default --expand-variable fix@{{HOME}}/.secret --expand-data "{{fix:trim:url}}" https://example.com/ Documented. Many new test cases. Co-brainstormed-by: Emanuele Torre Assisted-by: Jat Satiro Closes #11346
42 lines
1.8 KiB
C
42 lines
1.8 KiB
C
#ifndef HEADER_CURL_BASE64_H
|
|
#define HEADER_CURL_BASE64_H
|
|
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
|
|
#ifndef BUILDING_LIBCURL
|
|
/* this renames functions so that the tool code can use the same code
|
|
without getting symbol collisions */
|
|
#define Curl_base64_encode(a,b,c,d) curlx_base64_encode(a,b,c,d)
|
|
#define Curl_base64url_encode(a,b,c,d) curlx_base64url_encode(a,b,c,d)
|
|
#define Curl_base64_decode(a,b,c) curlx_base64_decode(a,b,c)
|
|
#endif
|
|
|
|
CURLcode Curl_base64_encode(const char *inputbuff, size_t insize,
|
|
char **outptr, size_t *outlen);
|
|
CURLcode Curl_base64url_encode(const char *inputbuff, size_t insize,
|
|
char **outptr, size_t *outlen);
|
|
CURLcode Curl_base64_decode(const char *src,
|
|
unsigned char **outptr, size_t *outlen);
|
|
#endif /* HEADER_CURL_BASE64_H */
|