|
commit 8d09dc21dc913d1540d07d1019a51c430317eae1
|
|
Author: Christopher Faulet <cfaulet@haproxy.com>
|
|
Date: Tue Jun 18 09:37:00 2019 +0200
|
|
|
|
MINOR: htx: Add the function htx_change_blk_value_len()
|
|
|
|
As its name suggest, this function change the value length of a block. But it
|
|
also update the HTX message accordingly. It simplifies the HTX API. The function
|
|
htx_set_blk_value_len() is still available and must be used with caution because
|
|
this one does not update the HTX message. It just updates the HTX block. It
|
|
should be considered as an internal function. When possible,
|
|
htx_change_blk_value_len() should be used instead.
|
|
|
|
This function is used to fix a bug affecting the 2.0. So, this patch must be
|
|
backported to 2.0.
|
|
|
|
(cherry picked from commit bb0efcdd293de33607a6eba075971b49857375e2)
|
|
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
|
|
|
|
diff --git a/include/common/htx.h b/include/common/htx.h
|
|
index 9631c618..7d15365a 100644
|
|
--- a/include/common/htx.h
|
|
+++ b/include/common/htx.h
|
|
@@ -470,7 +470,41 @@ static inline struct htx_blk *htx_get_next_blk(const struct htx *htx,
|
|
}
|
|
|
|
/* Changes the size of the value. It is the caller responsibility to change the
|
|
- * value itself, make sure there is enough space and update allocated value.
|
|
+ * value itself, make sure there is enough space and update allocated
|
|
+ * value. This function updates the HTX message accordingly.
|
|
+ */
|
|
+static inline void htx_change_blk_value_len(struct htx *htx, struct htx_blk *blk, uint32_t newlen)
|
|
+{
|
|
+ enum htx_blk_type type = htx_get_blk_type(blk);
|
|
+ uint32_t oldlen, sz;
|
|
+ int32_t delta;
|
|
+
|
|
+ sz = htx_get_blksz(blk);
|
|
+ switch (type) {
|
|
+ case HTX_BLK_HDR:
|
|
+ case HTX_BLK_TLR:
|
|
+ oldlen = (blk->info >> 8) & 0xfffff;
|
|
+ blk->info = (type << 28) + (newlen << 8) + (blk->info & 0xff);
|
|
+ break;
|
|
+ default:
|
|
+ oldlen = blk->info & 0xfffffff;
|
|
+ blk->info = (type << 28) + newlen;
|
|
+ break;
|
|
+ }
|
|
+
|
|
+ /* Update HTTP message */
|
|
+ delta = (newlen - oldlen);
|
|
+ htx->data += delta;
|
|
+ if (blk->addr+sz == htx->tail_addr)
|
|
+ htx->tail_addr += delta;
|
|
+ else if (blk->addr+sz == htx->head_addr)
|
|
+ htx->head_addr += delta;
|
|
+}
|
|
+
|
|
+/* Changes the size of the value. It is the caller responsibility to change the
|
|
+ * value itself, make sure there is enough space and update allocated
|
|
+ * value. Unlike the function htx_change_blk_value_len(), this one does not
|
|
+ * update the HTX message. So it should be used with caution.
|
|
*/
|
|
static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen)
|
|
{
|