h2/h3: provide and refer to pseudo headers as defines

... and do sizeof() on the defines to use constants better.

Closes #8389
This commit is contained in:
Daniel Stenberg 2022-02-04 16:57:38 +01:00
parent 793614b589
commit 136f3e9d68
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
4 changed files with 45 additions and 34 deletions

View File

@ -64,6 +64,11 @@
#define H2BUGF(x) do { } while(0)
#endif
#define H2_PSEUDO_METHOD ":method"
#define H2_PSEUDO_SCHEME ":scheme"
#define H2_PSEUDO_AUTHORITY ":authority"
#define H2_PSEUDO_PATH ":path"
#define H2_PSEUDO_STATUS ":status"
static ssize_t http2_recv(struct Curl_easy *data, int sockindex,
char *mem, size_t len, CURLcode *err);
@ -513,7 +518,7 @@ static int set_transfer_url(struct Curl_easy *data,
if(!u)
return 5;
v = curl_pushheader_byname(hp, ":scheme");
v = curl_pushheader_byname(hp, H2_PSEUDO_SCHEME);
if(v) {
uc = curl_url_set(u, CURLUPART_SCHEME, v, 0);
if(uc) {
@ -522,7 +527,7 @@ static int set_transfer_url(struct Curl_easy *data,
}
}
v = curl_pushheader_byname(hp, ":authority");
v = curl_pushheader_byname(hp, H2_PSEUDO_AUTHORITY);
if(v) {
uc = curl_url_set(u, CURLUPART_HOST, v, 0);
if(uc) {
@ -531,7 +536,7 @@ static int set_transfer_url(struct Curl_easy *data,
}
}
v = curl_pushheader_byname(hp, ":path");
v = curl_pushheader_byname(hp, H2_PSEUDO_PATH);
if(v) {
uc = curl_url_set(u, CURLUPART_PATH, v, 0);
if(uc) {
@ -1009,7 +1014,7 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
if(frame->hd.type == NGHTTP2_PUSH_PROMISE) {
char *h;
if(!strcmp(":authority", (const char *)name)) {
if(!strcmp(H2_PSEUDO_AUTHORITY, (const char *)name)) {
/* pseudo headers are lower case */
int rc = 0;
char *check = aprintf("%s:%d", conn->host.name, conn->remote_port);
@ -1072,8 +1077,8 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame,
return 0;
}
if(namelen == sizeof(":status") - 1 &&
memcmp(":status", name, namelen) == 0) {
if(namelen == sizeof(H2_PSEUDO_STATUS) - 1 &&
memcmp(H2_PSEUDO_STATUS, name, namelen) == 0) {
/* nghttp2 guarantees :status is received first and only once, and
value is 3 digits status code, and decode_status_code always
succeeds. */
@ -2010,8 +2015,8 @@ static ssize_t http2_send(struct Curl_easy *data, int sockindex,
end = memchr(hdbuf, ' ', line_end - hdbuf);
if(!end || end == hdbuf)
goto fail;
nva[0].name = (unsigned char *)":method";
nva[0].namelen = strlen((char *)nva[0].name);
nva[0].name = (unsigned char *)H2_PSEUDO_METHOD;
nva[0].namelen = sizeof(H2_PSEUDO_METHOD) - 1;
nva[0].value = (unsigned char *)hdbuf;
nva[0].valuelen = (size_t)(end - hdbuf);
nva[0].flags = NGHTTP2_NV_FLAG_NONE;
@ -2032,8 +2037,8 @@ static ssize_t http2_send(struct Curl_easy *data, int sockindex,
}
if(!end || end == hdbuf)
goto fail;
nva[1].name = (unsigned char *)":path";
nva[1].namelen = strlen((char *)nva[1].name);
nva[1].name = (unsigned char *)H2_PSEUDO_PATH;
nva[1].namelen = sizeof(H2_PSEUDO_PATH) - 1;
nva[1].value = (unsigned char *)hdbuf;
nva[1].valuelen = (size_t)(end - hdbuf);
nva[1].flags = NGHTTP2_NV_FLAG_NONE;
@ -2042,8 +2047,8 @@ static ssize_t http2_send(struct Curl_easy *data, int sockindex,
goto fail;
}
nva[2].name = (unsigned char *)":scheme";
nva[2].namelen = strlen((char *)nva[2].name);
nva[2].name = (unsigned char *) H2_PSEUDO_SCHEME;
nva[2].namelen = sizeof(H2_PSEUDO_SCHEME) - 1;
if(conn->handler->flags & PROTOPT_SSL)
nva[2].value = (unsigned char *)"https";
else
@ -2080,8 +2085,8 @@ static ssize_t http2_send(struct Curl_easy *data, int sockindex,
if(hlen == 4 && strncasecompare("host", hdbuf, 4)) {
authority_idx = i;
nva[i].name = (unsigned char *)":authority";
nva[i].namelen = strlen((char *)nva[i].name);
nva[i].name = (unsigned char *)H2_PSEUDO_AUTHORITY;
nva[i].namelen = sizeof(H2_PSEUDO_AUTHORITY) - 1;
}
else {
nva[i].namelen = (size_t)(end - hdbuf);

View File

@ -1079,8 +1079,8 @@ static int cb_h3_recv_header(nghttp3_conn *conn, int64_t stream_id,
(void)flags;
(void)user_data;
if(h3name.len == sizeof(":status") - 1 &&
!memcmp(":status", h3name.base, h3name.len)) {
if(h3name.len == sizeof(H3_PSEUDO_STATUS) - 1 &&
!memcmp(H3_PSEUDO_STATUS, h3name.base, h3name.len)) {
char line[14]; /* status line is always 13 characters long */
size_t ncopy;
int status = decode_status_code(h3val.base, h3val.len);
@ -1440,8 +1440,8 @@ static CURLcode http_request(struct Curl_easy *data, const void *mem,
end = memchr(hdbuf, ' ', line_end - hdbuf);
if(!end || end == hdbuf)
goto fail;
nva[0].name = (unsigned char *)":method";
nva[0].namelen = strlen((char *)nva[0].name);
nva[0].name = (unsigned char *)H3_PSEUDO_METHOD;
nva[0].namelen = sizeof(H3_PSEUDO_METHOD) - 1;
nva[0].value = (unsigned char *)hdbuf;
nva[0].valuelen = (size_t)(end - hdbuf);
nva[0].flags = NGHTTP3_NV_FLAG_NONE;
@ -1458,14 +1458,14 @@ static CURLcode http_request(struct Curl_easy *data, const void *mem,
}
if(!end || end == hdbuf)
goto fail;
nva[1].name = (unsigned char *)":path";
nva[1].namelen = strlen((char *)nva[1].name);
nva[1].name = (unsigned char *)H3_PSEUDO_PATH;
nva[1].namelen = sizeof(H3_PSEUDO_PATH) - 1;
nva[1].value = (unsigned char *)hdbuf;
nva[1].valuelen = (size_t)(end - hdbuf);
nva[1].flags = NGHTTP3_NV_FLAG_NONE;
nva[2].name = (unsigned char *)":scheme";
nva[2].namelen = strlen((char *)nva[2].name);
nva[2].name = (unsigned char *)H3_PSEUDO_SCHEME;
nva[2].namelen = sizeof(H3_PSEUDO_SCHEME) - 1;
if(conn->handler->flags & PROTOPT_SSL)
nva[2].value = (unsigned char *)"https";
else
@ -1499,8 +1499,8 @@ static CURLcode http_request(struct Curl_easy *data, const void *mem,
if(hlen == 4 && strncasecompare("host", hdbuf, 4)) {
authority_idx = i;
nva[i].name = (unsigned char *)":authority";
nva[i].namelen = strlen((char *)nva[i].name);
nva[i].name = (unsigned char *)H3_PSEUDO_AUTHORITY;
nva[i].namelen = sizeof(H3_PSEUDO_AUTHORITY) - 1;
}
else {
nva[i].namelen = (size_t)(end - hdbuf);

View File

@ -542,7 +542,7 @@ static int cb_each_header(uint8_t *name, size_t name_len,
struct h3h1header *headers = (struct h3h1header *)argp;
size_t olen = 0;
if((name_len == 7) && !strncmp(":status", (char *)name, 7)) {
if((name_len == 7) && !strncmp(H3_PSEUDO_STATUS, (char *)name, 7)) {
msnprintf(headers->dest,
headers->destlen, "HTTP/3 %.*s\n",
(int) value_len, value);
@ -759,8 +759,8 @@ static CURLcode http_request(struct Curl_easy *data, const void *mem,
end = memchr(hdbuf, ' ', line_end - hdbuf);
if(!end || end == hdbuf)
goto fail;
nva[0].name = (unsigned char *)":method";
nva[0].name_len = strlen((char *)nva[0].name);
nva[0].name = (unsigned char *)H3_PSEUDO_METHOD;
nva[0].name_len = sizeof(H3_PSEUDO_METHOD) - 1;
nva[0].value = (unsigned char *)hdbuf;
nva[0].value_len = (size_t)(end - hdbuf);
@ -776,13 +776,13 @@ static CURLcode http_request(struct Curl_easy *data, const void *mem,
}
if(!end || end == hdbuf)
goto fail;
nva[1].name = (unsigned char *)":path";
nva[1].name_len = strlen((char *)nva[1].name);
nva[1].name = (unsigned char *)H3_PSEUDO_PATH;
nva[1].name_len = sizeof(H3_PSEUDO_PATH) - 1;
nva[1].value = (unsigned char *)hdbuf;
nva[1].value_len = (size_t)(end - hdbuf);
nva[2].name = (unsigned char *)":scheme";
nva[2].name_len = strlen((char *)nva[2].name);
nva[2].name = (unsigned char *)H3_PSEUDO_SCHEME;
nva[2].name_len = sizeof(H3_PSEUDO_SCHEME) - 1;
if(conn->handler->flags & PROTOPT_SSL)
nva[2].value = (unsigned char *)"https";
else
@ -815,8 +815,8 @@ static CURLcode http_request(struct Curl_easy *data, const void *mem,
if(hlen == 4 && strncasecompare("host", hdbuf, 4)) {
authority_idx = i;
nva[i].name = (unsigned char *)":authority";
nva[i].name_len = strlen((char *)nva[i].name);
nva[i].name = (unsigned char *)H3_PSEUDO_AUTHORITY;
nva[i].name_len = sizeof(H3_PSEUDO_AUTHORITY) - 1;
}
else {
nva[i].name_len = (size_t)(end - hdbuf);

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2022, 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
@ -24,6 +24,12 @@
#include "curl_setup.h"
#define H3_PSEUDO_METHOD ":method"
#define H3_PSEUDO_SCHEME ":scheme"
#define H3_PSEUDO_AUTHORITY ":authority"
#define H3_PSEUDO_PATH ":path"
#define H3_PSEUDO_STATUS ":status"
#ifdef ENABLE_QUIC
CURLcode Curl_qlogdir(struct Curl_easy *data,
unsigned char *scid,