* - HTX_XFER_PARTIAL_HDRS_COPY: partial headers and trailers part can be xferred
* - HTX_XFER_HDRS_ONLY: Only the headers part is xferred
* - HTX_XFER_NO_METADATA: <count> don't include meta-data, only payload
+ * - HTX_XFER_KEEP_FIRST: the block in <dst> copied from the first block of
+ * <src> (htx->first) becomes the first block of <dst>.
+ * It is only supported if <dst> is empty, otherwise
+ * it is ignored. If the copy is rolled back, the
+ * first block of <dst> is reset when the block is
+ * removed, and the next added block will be the
+ * first one.
*/
size_t htx_xfer(struct htx *dst, struct htx *src, size_t count, unsigned int flags)
{
uint32_t max, last_dstblk_sz;
uint32_t nb_hdrs = 0;
int dst_full = 0;
+ int keep_first = ((flags & HTX_XFER_KEEP_FIRST) && htx_is_empty(dst));
/* Note: no test on the end of the message here. Blocks are added one by
* one below, using the safe functions. So invalid additions in a message
break;
}
+ /* The block was fully copied and is the tail block in <dst> */
+ if (keep_first && htx_get_blk_pos(src, blk) == src->first)
+ dst->first = htx_get_tail(dst);
+
last_dstblk = NULL; /* Reset last_dstblk because it was fully copied */
last_dstblk_sz = 0;
}
/* Move HTX blocks from <src> to <dst>. Relies on __htx_xfer_to_small_buffer() */
struct buffer *htx_move_to_small_buffer(struct buffer *dst, struct buffer *src)
{
- return __htx_xfer_to_small_buffer(dst, src, HTX_XFER_DEFAULT);
+ return __htx_xfer_to_small_buffer(dst, src, HTX_XFER_KEEP_FIRST);
}
/* Move HTX blocks from <src> to <dst>. Relies on __htx_xfer_to_large_buffer() */
struct buffer *htx_move_to_large_buffer(struct buffer *dst, struct buffer *src)
{
- return __htx_xfer_to_large_buffer(dst, src, HTX_XFER_DEFAULT);
+ return __htx_xfer_to_large_buffer(dst, src, HTX_XFER_KEEP_FIRST);
}
/* Copy HTX blocks from <src> to <dst>. Relies on __htx_xfer_to_small_buffer() */
struct buffer *htx_copy_to_small_buffer(struct buffer *dst, struct buffer *src)
{
- return __htx_xfer_to_small_buffer(dst, src, HTX_XFER_KEEP_SRC_BLKS);
+ return __htx_xfer_to_small_buffer(dst, src, HTX_XFER_KEEP_SRC_BLKS|HTX_XFER_KEEP_FIRST);
}
/* Copy HTX blocks from <src> to <dst>. Relies on __htx_xfer_to_large_buffer() */
struct buffer *htx_copy_to_large_buffer(struct buffer *dst, struct buffer *src)
{
- return __htx_xfer_to_large_buffer(dst, src, HTX_XFER_KEEP_SRC_BLKS);
+ return __htx_xfer_to_large_buffer(dst, src, HTX_XFER_KEEP_SRC_BLKS|HTX_XFER_KEEP_FIRST);
}