mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-18 03:30:43 +00:00
MINOR: htx: Add function to add an HTX block just before another one
The function htx_add_data_before() can be used to add an HTX block before another one. For instance, it could be used to add some data before the end-of-message marker.
This commit is contained in:
parent
9400a3924d
commit
24ed835129
@ -57,6 +57,7 @@ struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type type);
|
|||||||
struct htx_blk *htx_add_data(struct htx *htx, const struct ist data);
|
struct htx_blk *htx_add_data(struct htx *htx, const struct ist data);
|
||||||
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);
|
||||||
struct htx_blk *htx_add_oob(struct htx *htx, const struct ist oob);
|
struct htx_blk *htx_add_oob(struct htx *htx, const struct ist oob);
|
||||||
|
struct htx_blk *htx_add_data_before(struct htx *htx, const struct htx_blk *ref, const struct ist data);
|
||||||
|
|
||||||
int htx_reqline_to_str(const union htx_sl *sl, struct buffer *chk);
|
int htx_reqline_to_str(const union htx_sl *sl, struct buffer *chk);
|
||||||
int htx_stline_to_str(const union htx_sl *sl, struct buffer *chk);
|
int htx_stline_to_str(const union htx_sl *sl, struct buffer *chk);
|
||||||
|
31
src/htx.c
31
src/htx.c
@ -788,6 +788,37 @@ struct htx_blk *htx_add_oob(struct htx *htx, const struct ist oob)
|
|||||||
return blk;
|
return blk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct htx_blk *htx_add_data_before(struct htx *htx, const struct htx_blk *ref,
|
||||||
|
const struct ist data)
|
||||||
|
{
|
||||||
|
struct htx_blk *blk;
|
||||||
|
int32_t prev;
|
||||||
|
|
||||||
|
/* FIXME: check data.len (< 256MB) */
|
||||||
|
blk = htx_add_blk(htx, HTX_BLK_DATA, data.len);
|
||||||
|
if (!blk)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
blk->info += data.len;
|
||||||
|
memcpy(htx_get_blk_ptr(htx, blk), data.ptr, data.len);
|
||||||
|
|
||||||
|
for (prev = htx_get_prev(htx, htx->tail); prev != -1; prev = htx_get_prev(htx, prev)) {
|
||||||
|
struct htx_blk *pblk = htx_get_blk(htx, prev);
|
||||||
|
|
||||||
|
/* Swap .addr and .info fields */
|
||||||
|
blk->addr ^= pblk->addr; pblk->addr ^= blk->addr; blk->addr ^= pblk->addr;
|
||||||
|
blk->info ^= pblk->info; pblk->info ^= blk->info; blk->info ^= pblk->info;
|
||||||
|
|
||||||
|
if (blk->addr == pblk->addr)
|
||||||
|
blk->addr += htx_get_blksz(pblk);
|
||||||
|
htx->front = prev;
|
||||||
|
|
||||||
|
if (pblk == ref)
|
||||||
|
break;
|
||||||
|
blk = pblk;
|
||||||
|
}
|
||||||
|
return blk;
|
||||||
|
}
|
||||||
|
|
||||||
/* Appends the string representation of the request line block <blk> to the
|
/* Appends the string representation of the request line block <blk> to the
|
||||||
* chunk <chk>. It returns 1 if data are successfully appended, otherwise it
|
* chunk <chk>. It returns 1 if data are successfully appended, otherwise it
|
||||||
|
Loading…
Reference in New Issue
Block a user