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").
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 @@
/* 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 @@
/* 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;
}