]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: Add a function to copy a buffer in an HTX message
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 15 May 2020 12:52:49 +0000 (14:52 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 20 May 2020 16:27:14 +0000 (18:27 +0200)
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().

include/common/htx.h
src/http_ana.c

index 7bd12b407eefba49f7172e92b52c0ea348020336..3d54c4a0fcb0317ac51666f7b748f969da5bafff 100644 (file)
@@ -780,6 +780,22 @@ static inline int htx_is_not_empty(const struct htx *htx)
        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
  * illegal to call this function with htx == NULL. Note also blocks of type
  * HTX_BLK_UNUSED are part of used blocks.
index 138c0291c3d6e50476675e097e18179d8d76bedc..c93edfea759e97fa3211b35209ec361cc71d8deb 100644 (file)
@@ -4700,7 +4700,7 @@ int http_reply_message(struct stream *s, struct http_reply *reply)
                /* implicit or explicit error message*/
                errmsg = reply->body.errmsg;
                if (errmsg && !b_is_null(errmsg)) {
-                       if (!channel_htx_copy_msg(res, htx, errmsg))
+                       if (!htx_copy_msg(htx, errmsg))
                                goto fail;
                }
        }