]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx/channel: Add a function to copy an HTX message in a channel's buffer
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 23 Jan 2020 10:53:18 +0000 (11:53 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Feb 2020 13:55:16 +0000 (14:55 +0100)
The channel_htx_copy_msg() function can now be used to copy an HTX message in a
channel's buffer. This function takes care to not overwrite existing data.

This patch depends on the commit "MINOR: htx: Add a function to append an HTX
message to another one". Both are mandatory to fix a bug in
http_reply_and_close() function. Be careful to backport both first.

include/proto/channel.h

index 4872aa3cc1aca203d513184770407065eb126354..5411a74fc276477eae2c86612cb324da553e0336 100644 (file)
@@ -935,6 +935,22 @@ static inline int32_t channel_htx_fwd_headers(struct channel *chn, struct htx *h
        return pos;
 }
 
+/* Copy an HTX message stored in the buffer <msg> to the channel's one. We
+ * take care to not overwrite existing data in the channel. All the message is
+ * copied or nothing. It returns 1 on success and 0 on error.
+ */
+static inline int channel_htx_copy_msg(struct channel *chn, struct htx *htx, const struct buffer *msg)
+{
+       /* The channel buffer is empty, we can do a raw copy */
+       if (c_empty(chn)) {
+               chn->buf.data = msg->data;
+               memcpy(chn->buf.area, msg->area, msg->data);
+               return 1;
+       }
+
+       /* Otherwise, we need to append the HTX message */
+       return htx_append_msg(htx, htxbuf(msg));
+}
 /*
  * Advance the channel buffer's read pointer by <len> bytes. This is useful
  * when data have been read directly from the buffer. It is illegal to call