writeout: fix %{http_version} for HTTP/3

Output "3" properly when HTTP/3 was used.

Reported-by: Bernat Mut
Fixes #8072
Closes #8092
This commit is contained in:
Daniel Stenberg 2021-12-03 16:55:04 +01:00
parent 92d1aee8b1
commit cdde5414fc
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -45,12 +45,18 @@ static int writeOffset(FILE *stream, const struct writeoutvar *wovar,
struct per_transfer *per, CURLcode per_result, struct per_transfer *per, CURLcode per_result,
bool use_json); bool use_json);
static const char *http_version[] = { struct httpmap {
"0", /* CURL_HTTP_VERSION_NONE */ const char *str;
"1", /* CURL_HTTP_VERSION_1_0 */ int num;
"1.1", /* CURL_HTTP_VERSION_1_1 */ };
"2", /* CURL_HTTP_VERSION_2 */
"3" /* CURL_HTTP_VERSION_3 */ 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 /* 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) {
if(wovar->ci == CURLINFO_HTTP_VERSION) { if(wovar->ci == CURLINFO_HTTP_VERSION) {
long version = 0; long version = 0;
if(!curl_easy_getinfo(per->curl, CURLINFO_HTTP_VERSION, &version) && if(!curl_easy_getinfo(per->curl, CURLINFO_HTTP_VERSION, &version)) {
(version >= 0) && const struct httpmap *m = &http_version[0];
(version < (long)(sizeof(http_version)/sizeof(http_version[0])))) { while(m->str) {
strinfo = http_version[version]; if(m->num == version) {
valid = true; strinfo = m->str;
valid = true;
break;
}
m++;
}
} }
} }
else { else {