]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] http: support wrapping messages in error captures
authorWilly Tarreau <w@1wt.eu>
Sun, 12 Dec 2010 12:09:08 +0000 (13:09 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 12 Dec 2010 12:09:08 +0000 (13:09 +0100)
Error captures did only support contiguous messages. This is annoying
for capturing chunking errors, so let's ensure the function is able to
copy wrapped messages.

src/proto_http.c

index 670ecd11801a03542cf562f5f6cacbc3b0e4ce2d..2c33a84ce60230feba19254b770296110ddd9c11 100644 (file)
@@ -7222,12 +7222,25 @@ void http_capture_bad_message(struct error_snapshot *es, struct session *s,
                               struct buffer *buf, struct http_msg *msg,
                              int state, struct proxy *other_end)
 {
-       es->len = buf->r - (buf->data + msg->som);
-       memcpy(es->buf, buf->data + msg->som, MIN(es->len, sizeof(es->buf)));
+       if (buf->r <= (buf->data + msg->som)) { /* message wraps */
+               int len1 = buf->size - msg->som;
+               es->len = buf->r - (buf->data + msg->som) + buf->size;
+               memcpy(es->buf, buf->data + msg->som, MIN(len1, sizeof(es->buf)));
+               if (es->len > len1 && len1 < sizeof(es->buf))
+                       memcpy(es->buf, buf->data, MIN(es->len, sizeof(es->buf)) - len1);
+       }
+       else {
+               es->len = buf->r - (buf->data + msg->som);
+               memcpy(es->buf, buf->data + msg->som, MIN(es->len, sizeof(es->buf)));
+       }
+
        if (msg->err_pos >= 0)
                es->pos  = msg->err_pos - msg->som;
-       else
+       else if (buf->lr >= (buf->data + msg->som))
                es->pos  = buf->lr - (buf->data + msg->som);
+       else
+               es->pos  = buf->lr - (buf->data + msg->som) + buf->size;
+
        es->when = date; // user-visible date
        es->sid  = s->uniq_id;
        es->srv  = s->srv;