]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: Skip headers with no value when adding a header list to a message
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 9 Sep 2021 07:44:18 +0000 (09:44 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 10 Sep 2021 08:35:53 +0000 (10:35 +0200)
When the header list is added, after the message parsing, headers with no
value are now ignored. It is not the same than headers with empty value
fields. Only headers with a NULL pointer as value are skipped. This only
happens if the header value is removed during the message
parsing. Concretly, such headers are now ignored when htx_add_all_headers()
is called. However, htx_add_header() is not affected by this change.

Symetrically, the same is true for trailers. It may be backported to 2.4
because of the previous fix ("BUG/MEDIUM: mux-h1: Remove "Upgrade:" header
for requests with payload").

include/haproxy/htx.h

index a6535237b18ce78d01ef4ca88618082b3ba45853..93b3206a832d7890ef6fb0f93da4399f01a34e4c 100644 (file)
@@ -517,12 +517,19 @@ static inline struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type t
 
 /* Add all headers from the list <hdrs> into the HTX message <htx>, followed by
  * the EOH. On success, it returns the last block inserted (the EOH), otherwise
- * NULL is returned. */
+ * NULL is returned.
+ *
+ * Headers with a NULL value (.ptr == NULL) are ignored but not those with empty
+ * value (.len == 0 but .ptr != NULL)
+ */
 static inline struct htx_blk *htx_add_all_headers(struct htx *htx, const struct http_hdr *hdrs)
 {
        int i;
 
        for (i = 0; hdrs[i].n.len; i++) {
+               /* Don't check the value length because a header value may be empty */
+               if (isttest(hdrs[i].v) == 0)
+                       continue;
                if (!htx_add_header(htx, hdrs[i].n, hdrs[i].v))
                        return NULL;
        }
@@ -531,12 +538,19 @@ static inline struct htx_blk *htx_add_all_headers(struct htx *htx, const struct
 
 /* Add all trailers from the list <hdrs> into the HTX message <htx>, followed by
  * the EOT. On success, it returns the last block inserted (the EOT), otherwise
- * NULL is returned. */
+ * NULL is returned.
+ *
+ * Trailers with a NULL value (.ptr == NULL) are ignored but not those with
+ * empty value (.len == 0 but .ptr != NULL)
+ */
 static inline struct htx_blk *htx_add_all_trailers(struct htx *htx, const struct http_hdr *hdrs)
 {
        int i;
 
        for (i = 0; hdrs[i].n.len; i++) {
+               /* Don't check the value length because a header value may be empty */
+               if (isttest(hdrs[i].v) == 0)
+                       continue;
                if (!htx_add_trailer(htx, hdrs[i].n, hdrs[i].v))
                        return NULL;
        }