]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-htx: Add a function to retrieve the headers size of an HTX message
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Feb 2020 15:39:41 +0000 (16:39 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 18 Feb 2020 10:19:57 +0000 (11:19 +0100)
http_get_hdrs_size() function may now be used to get the bytes held by headers
in an HTX message. It only works if the headers were not already
forwarded. Metadata are not counted here.

include/proto/http_htx.h
src/http_htx.c

index 4b980e2cf5b60d36928a7a28d39e94256e578b8f..617417ad5ce61a14529f231bf51d626a68d71583 100644 (file)
@@ -32,6 +32,7 @@ extern struct buffer http_err_chunks[HTTP_ERR_SIZE];
 extern struct list http_errors_list;
 
 struct htx_sl *http_get_stline(struct htx *htx);
+size_t http_get_hdrs_size(struct htx *htx);
 int http_find_header(const struct htx *htx, const struct ist name, struct http_hdr_ctx *ctx, int full);
 int http_add_header(struct htx *htx, const struct ist n, const struct ist v);
 int http_replace_stline(struct htx *htx, const struct ist p1, const struct ist p2, const struct ist p3);
index 587b9a548acfa75c95341a8d3f2130e589470cd8..f2f0a0c18a862d638838e9abcb2b8fee1dd6ac0a 100644 (file)
@@ -72,6 +72,24 @@ struct htx_sl *http_get_stline(struct htx *htx)
        return htx_get_blk_ptr(htx, blk);
 }
 
+/* Returns the headers size in the HTX message */
+size_t http_get_hdrs_size(struct htx *htx)
+{
+       struct htx_blk *blk;
+       size_t sz = 0;
+
+       blk = htx_get_first_blk(htx);
+       if (!blk || htx_get_blk_type(blk) > HTX_BLK_EOH)
+               return sz;
+
+       for (; blk; blk = htx_get_next_blk(htx, blk)) {
+               sz += htx_get_blksz(blk);
+               if (htx_get_blk_type(blk) == HTX_BLK_EOH)
+                       break;
+       }
+       return sz;
+}
+
 /* Finds the first or next occurrence of header <name> in the HTX message <htx>
  * using the context <ctx>. This structure holds everything necessary to use the
  * header and find next occurrence. If its <blk> member is NULL, the header is