MINOR: htx: Don't try to append a trailer block with the previous one

In H1 and H2, one and only one trailer block is emitted during the HTTP
parsing. So it is useless to try to append this block with the previous one,
like for data block.

This patch may be backported to 1.9.
This commit is contained in:
Christopher Faulet 2019-05-07 21:42:27 +02:00
parent bc5770b91e
commit 6177509eb7

View File

@ -345,10 +345,10 @@ struct htx_ret htx_drain(struct htx *htx, uint32_t count)
} }
/* Tries to append data to the last inserted block, if the type matches and if /* Tries to append data to the last inserted block, if the type matches and if
* there is enough non-wrapping space. Only DATA and TRAILERS content can be * there is enough non-wrapping space. Only DATA content can be appended. If the
* appended. If the append fails, a new block is inserted. If an error occurred, * append fails, a new block is inserted. If an error occurred, NULL is
* NULL is returned. Otherwise, on success, the updated block (or the new one) * returned. Otherwise, on success, the updated block (or the new one) is
* is returned. * returned.
*/ */
static struct htx_blk *htx_append_blk_value(struct htx *htx, enum htx_blk_type type, static struct htx_blk *htx_append_blk_value(struct htx *htx, enum htx_blk_type type,
const struct ist data) const struct ist data)
@ -364,8 +364,8 @@ static struct htx_blk *htx_append_blk_value(struct htx *htx, enum htx_blk_type t
if (data.len > htx_free_data_space(htx)) if (data.len > htx_free_data_space(htx))
return NULL; return NULL;
/* Append only DATA et TRAILERS data */ /* Append only DATA */
if (type != HTX_BLK_DATA && type != HTX_BLK_TLR) if (type != HTX_BLK_DATA)
goto add_new_block; goto add_new_block;
/* get the tail and head block */ /* get the tail and head block */
@ -785,13 +785,21 @@ struct htx_blk *htx_add_data(struct htx *htx, const struct ist data)
return htx_append_blk_value(htx, HTX_BLK_DATA, data); return htx_append_blk_value(htx, HTX_BLK_DATA, data);
} }
/* Adds an HTX block of type TLR in <htx>. It first tries to append trailers /* Adds an HTX block of type TLR in <htx>. It returns the new block on
* data if possible. It returns the new block on success. Otherwise, it returns * success. Otherwise, it returns NULL.
* NULL.
*/ */
struct htx_blk *htx_add_trailer(struct htx *htx, const struct ist tlr) struct htx_blk *htx_add_trailer(struct htx *htx, const struct ist tlr)
{ {
return htx_append_blk_value(htx, HTX_BLK_TLR, tlr); struct htx_blk *blk;
/* FIXME: check tlr.len (< 256MB) */
blk = htx_add_blk(htx, HTX_BLK_TLR, tlr.len);
if (!blk)
return NULL;
blk->info += tlr.len;
memcpy(htx_get_blk_ptr(htx, blk), tlr.ptr, tlr.len);
return blk;
} }
/* Adds an HTX block of type OOB in <htx>. It returns the new block on /* Adds an HTX block of type OOB in <htx>. It returns the new block on