]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
h2/h3: provide and refer to pseudo headers as defines
authorDaniel Stenberg <daniel@haxx.se>
Fri, 4 Feb 2022 15:57:38 +0000 (16:57 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 5 Feb 2022 10:08:43 +0000 (11:08 +0100)
... and do sizeof() on the defines to use constants better.

Closes #8389

lib/http2.c
lib/vquic/ngtcp2.c
lib/vquic/quiche.c
lib/vquic/vquic.h

index 652be3f8afe8cf1915a2bbfe726bcb517f727ee0..b5e322bcabf491e18397bd184f937ff0bcdef34e 100644 (file)
 #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);
index 81eb0bd0a39859383acf39a06627288cba6c4698..102310d73a388568964f2e42b498d0c87aba4c74 100644 (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);
index 1bff3753e22d199d8e8d86528cc8abd40039ae24..908c56bc9a5bfa783d0267d852691758f5492592 100644 (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);
index eb8a893d925a478e631344078ba69d037988415b..adad5846b2a9bbc9effc5f93e18d41c70087b260 100644 (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
 
 #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,