* zero-copy is performed. It returns the number of bytes copied.
*/
static size_t h1_copy_msg_data(struct htx **dsthtx, struct buffer *srcbuf, size_t ofs,
- size_t count, size_t max, struct buffer *htxbuf)
+ size_t count, size_t max, struct buffer *htxbuf,
+ enum htx_blk_type type)
{
struct htx *tmp_htx = *dsthtx;
size_t block1, block2, ret = 0;
htx_reset(tmp_htx);
b_set_data(htxbuf, b_size(htxbuf));
- blk = htx_add_blk(tmp_htx, HTX_BLK_DATA, count);
+ blk = htx_add_blk(tmp_htx, type, count);
blk->info += count;
*dsthtx = tmp_htx;
block2 = max;
}
- ret = htx_add_data(tmp_htx, ist2(b_peek(srcbuf, ofs), block1));
+ ret = htx_add_data_type(tmp_htx, ist2(b_peek(srcbuf, ofs), block1), type);
if (ret == block1 && block2)
- ret += htx_add_data(tmp_htx, ist2(b_orig(srcbuf), block2));
+ ret += htx_add_data_type(tmp_htx, ist2(b_orig(srcbuf), block2), type);
end:
return ret;
}
sz = b_data(srcbuf) - ofs;
if (unlikely(sz > h1m->curr_len))
sz = h1m->curr_len;
- sz = h1_copy_msg_data(dsthtx, srcbuf, ofs, sz, lmax, htxbuf);
+ sz = h1_copy_msg_data(dsthtx, srcbuf, ofs, sz, lmax, htxbuf, HTX_BLK_DATA);
lmax -= htx_used_space(*dsthtx) - used;
ofs += sz;
total += sz;
sz = b_data(srcbuf) - ofs;
if (unlikely(sz > h1m->curr_len))
sz = h1m->curr_len;
- sz = h1_copy_msg_data(dsthtx, srcbuf, ofs, sz, max, htxbuf);
+ sz = h1_copy_msg_data(dsthtx, srcbuf, ofs, sz, max, htxbuf, HTX_BLK_DATA);
h1m->curr_len -= sz;
total += sz;
if (!h1m->curr_len) {
htx_set_eom(*dsthtx);
}
else {
- /* no content length, read till SHUTW */
+ /* no content length, read till SHUTW. In TUNNEL state, these
+ * data are tunneled data. They must not be mixed with HTTP
+ * data, so a dedicated block type is used for them.
+ */
sz = b_data(srcbuf) - ofs;
- sz = h1_copy_msg_data(dsthtx, srcbuf, ofs, sz, max, htxbuf);
+ sz = h1_copy_msg_data(dsthtx, srcbuf, ofs, sz, max, htxbuf,
+ (h1m->state == H1_MSG_TUNNEL ? HTX_BLK_RAW_DATA : HTX_BLK_DATA));
total += sz;
h1m->body_len += sz;
}