]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h1: make h1_measure_trailers() use an offset and a count
authorWilly Tarreau <w@1wt.eu>
Thu, 14 Jun 2018 14:52:02 +0000 (16:52 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Jul 2018 14:23:41 +0000 (16:23 +0200)
This will be needed by the H2 encoder to restart after wrapping.

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

index b0051e3a9d6209226ad32bf166ab2f2e95ea2211..943ac0fe5e82f835d7d5048b8ee8de17640dbd63 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, unsigned int max);
+int h1_measure_trailers(const struct buffer *buf, unsigned int ofs, unsigned int max);
 
 #define H1_FLG_CTL  0x01
 #define H1_FLG_SEP  0x02
index 436180952c3cab3afc142bdd6ad1f427b882504c..12278f470464d81408907cb6d91aeaaafcc8a2d0 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -1209,19 +1209,19 @@ 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> for up to <max> bytes, and returns the number of
+ * at offset <ofs> in <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, unsigned int max)
+int h1_measure_trailers(const struct buffer *buf, unsigned int ofs, unsigned int max)
 {
-       int count = 0;
+       const char *stop = b_peek(buf, ofs + max);
+       int count = ofs;
 
        while (1) {
                const char *p1 = NULL, *p2 = NULL;
                const char *start = b_peek(buf, count);
-               const char *stop  = b_peek(buf, max);
                const char *ptr   = start;
 
                /* scan current line and stop at LF or CRLF */
@@ -1256,7 +1256,7 @@ int h1_measure_trailers(const struct buffer *buf, unsigned int max)
                        break;
                /* OK, next line then */
        }
-       return count;
+       return count - ofs;
 }
 
 /* This function skips trailers in the buffer associated with HTTP message
index e75a2ba6470591c946e695a872887aea814cab17..63b49c175ec43dc9dcd862aefb0875c9b3f8b01c 100644 (file)
@@ -3400,7 +3400,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) */
-                       ret = h1_measure_trailers(buf, buf->o);
+                       ret = h1_measure_trailers(buf, 0, buf->o);
 
                        if (unlikely((int)ret <= 0)) {
                                if ((int)ret < 0)