From f079f44096cf78c18880e5b0d9279a168bd4b44e Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 9 Sep 2021 09:44:18 +0200 Subject: [PATCH] MINOR: htx: Skip headers with no value when adding a header list to a message 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 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/include/haproxy/htx.h b/include/haproxy/htx.h index a653523..93b3206 100644 --- a/include/haproxy/htx.h +++ b/include/haproxy/htx.h @@ -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 into the HTX message , 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 into the HTX message , 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; } -- 1.7.10.4