summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-12-03 16:55:04 +0100
committerDaniel Stenberg <daniel@haxx.se>2021-12-03 16:55:04 +0100
commit1fa05b1eb2cdbbf60ff5bc35b184de29d7e30570 (patch)
tree58d4021ed53f35568bdb9ea30195c78070695d55
parent3199eb25dc20c15b01f1e5aa4b38195ac042ff61 (diff)
downloadcurl-bagder/writeout-http_version.tar.gz
writeout: fix %{http_version} for HTTP/3bagder/writeout-http_version
Output "3" properly when HTTP/3 was used. Reported-by: Bernat Mut Fixes #8072
-rw-r--r--src/tool_writeout.c33
1 files changed, 22 insertions, 11 deletions
diff --git a/src/tool_writeout.c b/src/tool_writeout.c
index ed7a3418e..5b22a1a9c 100644
--- a/src/tool_writeout.c
+++ b/src/tool_writeout.c
@@ -45,12 +45,18 @@ static int writeOffset(FILE *stream, const struct writeoutvar *wovar,
struct per_transfer *per, CURLcode per_result,
bool use_json);
-static const char *http_version[] = {
- "0", /* CURL_HTTP_VERSION_NONE */
- "1", /* CURL_HTTP_VERSION_1_0 */
- "1.1", /* CURL_HTTP_VERSION_1_1 */
- "2", /* CURL_HTTP_VERSION_2 */
- "3" /* CURL_HTTP_VERSION_3 */
+struct httpmap {
+ const char *str;
+ int num;
+};
+
+static const struct httpmap http_version[] = {
+ { "0", CURL_HTTP_VERSION_NONE},
+ { "1", CURL_HTTP_VERSION_1_0},
+ { "1.1", CURL_HTTP_VERSION_1_1},
+ { "2", CURL_HTTP_VERSION_2},
+ { "3", CURL_HTTP_VERSION_3},
+ { NULL, 0} /* end of list */
};
/* The designated write function should be the same as the CURLINFO return type
@@ -165,11 +171,16 @@ static int writeString(FILE *stream, const struct writeoutvar *wovar,
if(wovar->ci) {
if(wovar->ci == CURLINFO_HTTP_VERSION) {
long version = 0;
- if(!curl_easy_getinfo(per->curl, CURLINFO_HTTP_VERSION, &version) &&
- (version >= 0) &&
- (version < (long)(sizeof(http_version)/sizeof(http_version[0])))) {
- strinfo = http_version[version];
- valid = true;
+ if(!curl_easy_getinfo(per->curl, CURLINFO_HTTP_VERSION, &version)) {
+ const struct httpmap *m = &http_version[0];
+ while(m->str) {
+ if(m->num == version) {
+ strinfo = m->str;
+ valid = true;
+ break;
+ }
+ m++;
+ }
}
}
else {