]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: htx: Add HTX_BLK_RAW_DATA block type
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 15 Sep 2026 11:58:34 +0000 (13:58 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 18 Sep 2026 15:05:18 +0000 (17:05 +0200)
An HTX message is a partial and stateless representation of an HTTP
message. Tunneled data are not part of the HTTP message. However, for now,
they are stored in DATA blocks, exactly like the HTTP payload. So there is
no way to make the difference between both.

A dedicated block type, HTX_BLK_RAW_DATA, is added to fix this. For now, no
producer emits such block. Only the HTX API is able to handle it. From this
point of view, a RAW_DATA block is exactly the same as a DATA block. Both
carry a payload that may be partially consumed. htx_is_data_type() function
was added to test this property on a block type.

It is important to add the new type in htx_get_blk_value() and
htx_set_blk_value_len() switches. Both have a default case silently doing
nothing. So a missing entry would lead to an empty payload on one side and
to a size never updated on the other side.

include/haproxy/htx-t.h
include/haproxy/htx.h

index af4d1436465dc77a3bc52604c6224ff24add7052..70f82f356a43dbcb7c0df2a21ef3137044962cae 100644 (file)
@@ -209,7 +209,8 @@ enum htx_blk_type {
        HTX_BLK_DATA   =  4, /* data block */
        HTX_BLK_TLR    =  5, /* trailer name/value block */
        HTX_BLK_EOT    =  6, /* end-of-trailers block */
-       /* 7 .. 14 unused */
+       HTX_BLK_RAW_DATA = 7, /* raw data block (tunneled data) */
+       /* 8 .. 14 unused */
        HTX_BLK_UNUSED = 15, /* unused/removed block */
 };
 
index 14f4e3c86acb7a204db543c303a6dc9b2b1fef7c..34b9f83ad516eaef46f6a5951578f45d3840c13d 100644 (file)
@@ -191,6 +191,14 @@ static inline enum htx_blk_type __htx_blkinfo_size(uint32_t info)
        }
 }
 
+/* Returns 1 if <type> is a payload type, i.e. a block carrying data that may be
+ * partially consumed (HTTP data or tunneled data). Otherwise 0 is returned.
+ */
+static inline int htx_is_data_type(enum htx_blk_type type)
+{
+       return (type == HTX_BLK_DATA || type == HTX_BLK_RAW_DATA);
+}
+
 /* Returns the size of the block <blk>, depending of its type */
 static inline uint32_t htx_get_blksz(const struct htx_blk *blk)
 {
@@ -421,6 +429,7 @@ static inline void htx_set_blk_value_len(struct htx_blk *blk, uint32_t vlen)
                case HTX_BLK_REQ_SL:
                case HTX_BLK_RES_SL:
                case HTX_BLK_DATA:
+               case HTX_BLK_RAW_DATA:
                        blk->info = (type << 28) + vlen;
                        break;
                default:
@@ -475,6 +484,7 @@ static inline struct ist htx_get_blk_value(const struct htx *htx, const struct h
                case HTX_BLK_REQ_SL:
                case HTX_BLK_RES_SL:
                case HTX_BLK_DATA:
+               case HTX_BLK_RAW_DATA:
                        ret = ist2(htx_get_blk_ptr(htx, blk),
                                   blk->info & 0xfffffff);
                        break;
@@ -875,6 +885,7 @@ static inline int htx_set_eom(struct htx *htx)
        }
 
        blk = ASSUME_NONNULL(htx_get_tail_blk(htx));
+
        BUG_ON(htx_get_blk_type(blk) != HTX_BLK_EOH &&
               htx_get_blk_type(blk) != HTX_BLK_EOT &&
               htx_get_blk_type(blk) != HTX_BLK_DATA);
@@ -942,6 +953,7 @@ static inline const char *htx_blk_type_str(enum htx_blk_type type)
                case HTX_BLK_HDR:    return "HTX_BLK_HDR";
                case HTX_BLK_EOH:    return "HTX_BLK_EOH";
                case HTX_BLK_DATA:   return "HTX_BLK_DATA";
+               case HTX_BLK_RAW_DATA: return "HTX_BLK_RAW_DATA";
                case HTX_BLK_TLR:    return "HTX_BLK_TLR";
                case HTX_BLK_EOT:    return "HTX_BLK_EOT";
                case HTX_BLK_UNUSED: return "HTX_BLK_UNUSED";