]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h1: make h1_measure_trailers() take the byte count in argument
authorWilly Tarreau <w@1wt.eu>
Thu, 14 Jun 2018 11:32:50 +0000 (13:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:40 +0000 (16:23 +0200)
The principle is that it should not have to take this value from the
buffer itself anymore.

include/proto/h1.h
src/h1.c
src/mux_h2.c

index ada7d03b6b15f193fa7cf53297c4c9691986f7e8..05d187740919cd5b69fe3e571118b807079c16a3 100644 (file)
@@ -43,7 +43,7 @@ int http_forward_trailers(struct http_msg *msg);
 int h1_headers_to_hdr_list(char *start, const char *stop,
                            struct http_hdr *hdr, unsigned int hdr_num,
                            struct h1m *h1m);
-int h1_measure_trailers(const struct buffer *buf);
+int h1_measure_trailers(const struct buffer *buf, unsigned int max);
 
 #define H1_FLG_CTL  0x01
 #define H1_FLG_SEP  0x02
index f0701163a3fbac162f43db335349ac47834ef61e..436180952c3cab3afc142bdd6ad1f427b882504c 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -1209,21 +1209,20 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
 }
 
 /* This function performs a very minimal parsing of the trailers block present
- * in the output part of <buf>, and returns the number of bytes to delete to
- * skip the trailers. It may return 0 if it's missing some input data, or < 0
- * in case of parse error (in which case the caller may have to decide how to
- * proceed, possibly eating everything).
+ * in the output part of <buf> for up to <max> bytes, and returns the number of
+ * bytes to delete to skip the trailers. It may return 0 if it's missing some
+ * input data, or < 0 in case of parse error (in which case the caller may have
+ * to decide how to proceed, possibly eating everything).
  */
-int h1_measure_trailers(const struct buffer *buf)
+int h1_measure_trailers(const struct buffer *buf, unsigned int max)
 {
        int count = 0;
 
        while (1) {
                const char *p1 = NULL, *p2 = NULL;
-               const char *start = b_ptr(buf, (int)(count - buf->o));
-               const char *stop  = b_peek(buf, buf->o);
+               const char *start = b_peek(buf, count);
+               const char *stop  = b_peek(buf, max);
                const char *ptr   = start;
-               int bytes = 0;
 
                /* scan current line and stop at LF or CRLF */
                while (1) {
@@ -1243,21 +1242,12 @@ int h1_measure_trailers(const struct buffer *buf)
                                p1 = ptr;
                        }
 
-                       ptr++;
-                       if (ptr >= buf->data + buf->size)
-                               ptr = buf->data;
+                       ptr = b_next(buf, ptr);
                }
 
                /* after LF; point to beginning of next line */
-               p2++;
-               if (p2 >= buf->data + buf->size)
-                       p2 = buf->data;
-
-               bytes = p2 - start;
-               if (bytes < 0)
-                       bytes += buf->size;
-
-               count += bytes;
+               p2 = b_next(buf, p2);
+               count += b_dist(buf, start, p2);
 
                /* LF/CRLF at beginning of line => end of trailers at p2.
                 * Everything was scheduled for forwarding, there's nothing left
index 9b4dcd52670c7863b7952ea02954f1dfae5ae805..beb7dca2885624e5f6b1e72e979f07b4837de4bb 100644 (file)
@@ -3391,7 +3391,7 @@ static int h2_snd_buf(struct conn_stream *cs, struct buffer *buf, int flags)
                }
                else if (h2s->res.state == HTTP_MSG_TRAILERS) {
                        /* consume the trailers if any (we don't forward them for now) */
-                       int count = h1_measure_trailers(buf);
+                       int count = h1_measure_trailers(buf, buf->o);
 
                        if (unlikely(count <= 0)) {
                                if (count < 0)