mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-28 22:31:06 +01:00
MINOR: htx: Add a function to copy a buffer in an HTX message
The htx_copy_msg() function can now be used to copy the HTX message stored in a buffer in an existing HTX message. It takes care to not overwrite existing data. If the destination message is empty, a raw copy is performed. All the message is copied or nothing. This function is used instead of channel_htx_copy_msg().
This commit is contained in:
parent
f1fedc3cce
commit
2056736453
@ -780,6 +780,22 @@ static inline int htx_is_not_empty(const struct htx *htx)
|
|||||||
return (htx->head != -1);
|
return (htx->head != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Copy an HTX message stored in the buffer <msg> to <htx>. We take care to
|
||||||
|
* not overwrite existing data. All the message is copied or nothing. It returns
|
||||||
|
* 1 on success and 0 on error.
|
||||||
|
*/
|
||||||
|
static inline int htx_copy_msg(struct htx *htx, const struct buffer *msg)
|
||||||
|
{
|
||||||
|
/* The destination HTX message is empty, we can do a raw copy */
|
||||||
|
if (htx_is_empty(htx)) {
|
||||||
|
memcpy(htx, msg->area, msg->size);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise, we need to append the HTX message */
|
||||||
|
return htx_append_msg(htx, htxbuf(msg));
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns the number of used blocks in the HTX message <htx>. Note that it is
|
/* Returns the number of used blocks in the HTX message <htx>. Note that it is
|
||||||
* illegal to call this function with htx == NULL. Note also blocks of type
|
* illegal to call this function with htx == NULL. Note also blocks of type
|
||||||
* HTX_BLK_UNUSED are part of used blocks.
|
* HTX_BLK_UNUSED are part of used blocks.
|
||||||
|
|||||||
@ -4700,7 +4700,7 @@ int http_reply_message(struct stream *s, struct http_reply *reply)
|
|||||||
/* implicit or explicit error message*/
|
/* implicit or explicit error message*/
|
||||||
errmsg = reply->body.errmsg;
|
errmsg = reply->body.errmsg;
|
||||||
if (errmsg && !b_is_null(errmsg)) {
|
if (errmsg && !b_is_null(errmsg)) {
|
||||||
if (!channel_htx_copy_msg(res, htx, errmsg))
|
if (!htx_copy_msg(htx, errmsg))
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user