BUG/MINOR: httpclient: Revisit HC request and response buffers allocation
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 12 Jan 2022 10:14:08 +0000 (11:14 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Feb 2022 13:40:05 +0000 (14:40 +0100)
commita9915308a4e52ba72ebe787be9cae48746e58c65
tree3b678ba21935151457bd4e6d3bb0b15d6f7256ad
parent3fb124ff7feb3e6f898b24ee36bfee154eba55c8
BUG/MINOR: httpclient: Revisit HC request and response buffers allocation

For now, these buffers are allocated when the httpclient is created and
freed when it is released. Usually, we try to avoid to keep buffer allocated
if it is not required. Empty buffers should be released ASAP. Apart for
that, there is no issue with the response side because a copy is always
performed. However, for the request side, a swap with the channel's buffer
is always performed. And there is no guarantee the channel's buffer is
allocated. Thus, after the swap, the httpclient can retrieve a null
buffer. In practice, this never happens. But this may change. And it will be
required for a futur fix.

So, now, we systematically take care to have an allocated buffer when we
want to write in it. And it is released as soon as it becomes empty.

This patch should be backported to 2.5.

(cherry picked from commit 600985df41c9777b6322f00e26dbf539f786d66f)
Signed-off-by: Willy Tarreau <w@1wt.eu>
src/http_client.c