MINOR: http-htx: Add a function to retrieve the headers size of an HTX message
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.
(cherry picked from commit 727a3f1ca3b32248d84499fe6bc554e3acaf5af7)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 3adcf7ec66de85a34363f7f5b48a4553acd6d412)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/http_htx.c b/src/http_htx.c
index d35904c..98d594b 100644
--- a/src/http_htx.c
+++ b/src/http_htx.c
@@ -37,6 +37,24 @@
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