]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: add http_hdr_del() to remove a header from a list
authorWilly Tarreau <w@1wt.eu>
Fri, 14 Sep 2018 15:32:05 +0000 (17:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Sep 2018 15:40:35 +0000 (17:40 +0200)
This one removes all occurrences of the specified header field name from
a complete list and returns the new count.

include/common/http-hdr.h

index a0bb341bbb049405a87c7797f0cbf919f0091bdc..8cc7ee7830e3ee87cd651e231c353005ba4047a5 100644 (file)
@@ -47,4 +47,21 @@ static inline void http_set_hdr(struct http_hdr *hdr, const struct ist n, const
        hdr->v = v;
 }
 
+/* removes all occurrences of header name <n> in list <hdr> and returns the new count. The
+ * list must be terminated by the empty header.
+ */
+static inline int http_del_hdr(struct http_hdr *hdr, const struct ist n)
+{
+       int src = 0, dst = 0;
+
+       do {
+               if (!isteqi(hdr[src].n, n)) {
+                       if (src != dst)
+                               hdr[dst] = hdr[src];
+                       dst++;
+               }
+       } while (hdr[src++].n.len);
+
+       return dst;
+}
 #endif /* _COMMON_HTTP_HDR_H */