curl: add %{header_json} support in -w handling

Outputs all response headers as a JSON object.
This commit is contained in:
Daniel Stenberg 2022-03-17 17:55:06 +01:00
parent 2d45137e1e
commit 4133a69f2d
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 66 additions and 10 deletions

View file

@ -75,6 +75,7 @@ static const struct writeoutvar variables[] = {
{"exitcode", VAR_EXITCODE, 0, writeLong},
{"filename_effective", VAR_EFFECTIVE_FILENAME, 0, writeString},
{"ftp_entry_path", VAR_FTP_ENTRY_PATH, CURLINFO_FTP_ENTRY_PATH, writeString},
{"header_json", VAR_HEADER_JSON, 0, NULL},
{"http_code", VAR_HTTP_CODE, CURLINFO_RESPONSE_CODE, writeLong},
{"http_connect", VAR_HTTP_CODE_PROXY, CURLINFO_HTTP_CONNECTCODE, writeLong},
{"http_version", VAR_HTTP_VERSION, CURLINFO_HTTP_VERSION, writeString},
@ -218,9 +219,8 @@ static int writeString(FILE *stream, const struct writeoutvar *wovar,
if(valid) {
DEBUGASSERT(strinfo);
if(use_json) {
fprintf(stream, "\"%s\":\"", wovar->name);
fprintf(stream, "\"%s\":", wovar->name);
jsonWriteString(stream, strinfo);
fputs("\"", stream);
}
else
fputs(strinfo, stream);
@ -366,6 +366,9 @@ void ourWriteOut(const char *writeinfo, struct per_transfer *per,
case VAR_JSON:
ourWriteOutJSON(stream, variables, per, per_result);
break;
case VAR_HEADER_JSON:
headerJSON(stream, per);
break;
default:
(void)variables[i].writefunc(stream, &variables[i],
per, per_result, false);