From fbdb0a991a449af0294dd09846fa4ecfda5d9f03 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 12 Mar 2026 14:54:20 +0100 Subject: [PATCH] MINOR: htx: Add function to truncate all blocks after a specific block htx_truncated_blk() function does the same than htx_trunctate(), except data are truncated relatively to a block in the message instead of an offset. --- include/haproxy/htx.h | 1 + src/htx.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/haproxy/htx.h b/include/haproxy/htx.h index 6a905a731..aad49c2da 100644 --- a/include/haproxy/htx.h +++ b/include/haproxy/htx.h @@ -37,6 +37,7 @@ struct htx_blk *htx_add_blk(struct htx *htx, enum htx_blk_type type, uint32_t bl struct htx_blk *htx_remove_blk(struct htx *htx, struct htx_blk *blk); struct htx_ret htx_find_offset(struct htx *htx, uint32_t offset); void htx_truncate(struct htx *htx, uint32_t offset); +void htx_truncate_blk(struct htx *htx, struct htx_blk *blk); struct htx_ret htx_drain(struct htx *htx, uint32_t max); struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk, diff --git a/src/htx.c b/src/htx.c index 5b64a8db4..cb8fd3770 100644 --- a/src/htx.c +++ b/src/htx.c @@ -469,6 +469,18 @@ void htx_truncate(struct htx *htx, uint32_t offset) blk = htx_remove_blk(htx, blk); } +/* Removes all blocks after , excluding it. if is NULL, all blocks + * are removed. + */ +void htx_truncate_blk(struct htx *htx, struct htx_blk *blk) +{ + if (!blk) { + htx_drain(htx, htx->data); + return; + } + for (blk = htx_get_next_blk(htx, blk); blk; blk = htx_remove_blk(htx, blk)); +} + /* Drains bytes from the HTX message . If the last block is a DATA * block, it will be cut if necessary. Others blocks will be removed at once if * is large enough. The function returns an htx_ret with the first block