]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: config: set tune.maxrewrite to 1024 by default
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Sep 2015 11:53:23 +0000 (13:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Sep 2015 11:59:41 +0000 (13:59 +0200)
The tune.maxrewrite parameter used to be pre-initialized to half of
the buffer size since the very early days when buffers were very small.
It has grown to absurdly large values over the years to reach 8kB for a
16kB buffer. This prevents large requests from being accepted, which is
the opposite of the initial goal.

Many users fix it to 1024 which is already quite large for header
addition.

So let's change the default setting policy :
  - pre-initialize it to 1024
  - let the user tweak it
  - in any case, limit it to tune.bufsize / 2

This results in 15kB usable to buffer HTTP messages instead of 8kB, and
doesn't affect existing configurations which already force it.

include/common/defaults.h
src/cfgparse.c
src/haproxy.c

index 02962010e70b01b464aaca63fd850ece31201e9a..d1994e83f60a3caa914df74942026b1d48d8b5c1 100644 (file)
@@ -28,8 +28,8 @@
  * when reading HTTP headers, the proxy needs some spare space to add or rewrite
  * headers if needed. The size of this spare is defined with MAXREWRITE. So it
  * is not possible to process headers longer than BUFSIZE-MAXREWRITE bytes. By
- * default, BUFSIZE=16384 bytes and MAXREWRITE=BUFSIZE/2, so the maximum length
- * of headers accepted is 8192 bytes, which is in line with Apache's limits.
+ * default, BUFSIZE=16384 bytes and MAXREWRITE=min(1024,BUFSIZE/2), so the
+ * maximum length of headers accepted is 15360 bytes.
  */
 #ifndef BUFSIZE
 #define BUFSIZE                16384
@@ -51,7 +51,7 @@
 
 // reserved buffer space for header rewriting
 #ifndef MAXREWRITE
-#define MAXREWRITE      (BUFSIZE / 2)
+#define MAXREWRITE      1024
 #endif
 
 #ifndef REQURI_LEN
index f7944c3aa41d569cd7da72593908970170f7b697..d732ac3286144e4c7a36e9cd94fb6f011a964afe 100644 (file)
@@ -833,8 +833,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
-               if (global.tune.maxrewrite >= global.tune.bufsize / 2)
-                       global.tune.maxrewrite = global.tune.bufsize / 2;
                chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize);
                alloc_trash_buffers(global.tune.bufsize);
        }
@@ -847,8 +845,11 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
                global.tune.maxrewrite = atol(args[1]);
-               if (global.tune.maxrewrite >= global.tune.bufsize / 2)
-                       global.tune.maxrewrite = global.tune.bufsize / 2;
+               if (global.tune.maxrewrite < 0) {
+                       Alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
        }
        else if (!strcmp(args[0], "tune.idletimer")) {
                unsigned int idle;
index a20f4977be89bef0d75b9ca93791f27762faa446..bdfa31824e1cdefa9541a097424a92630d826093 100644 (file)
@@ -150,7 +150,7 @@ struct global global = {
        },
        .tune = {
                .bufsize = BUFSIZE,
-               .maxrewrite = MAXREWRITE,
+               .maxrewrite = -1,
                .chksize = BUFSIZE,
                .reserved_bufs = RESERVED_BUFS,
                .pattern_cache = DEFAULT_PAT_LRU_SIZE,
@@ -1018,6 +1018,9 @@ void init(int argc, char **argv)
        if (global.tune.recv_enough == 0)
                global.tune.recv_enough = MIN_RECV_AT_ONCE_ENOUGH;
 
+       if (global.tune.maxrewrite < 0)
+               global.tune.maxrewrite = MAXREWRITE;
+
        if (global.tune.maxrewrite >= global.tune.bufsize / 2)
                global.tune.maxrewrite = global.tune.bufsize / 2;