MINOR: compression: tune.comp.maxlevel

This option allows you to set the maximum compression level usable by
the compression algorithm. It affects CPU usage.
diff --git a/doc/configuration.txt b/doc/configuration.txt
index c6eed08..f624abb 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -465,6 +465,7 @@
    - spread-checks
    - tune.bufsize
    - tune.chksize
+   - tune.comp.maxlevel
    - tune.http.maxhdr
    - tune.maxaccept
    - tune.maxpollevents
@@ -753,6 +754,12 @@
   build time. It is not recommended to change this value, but to use better
   checks whenever possible.
 
+tune.comp.maxlevel <number>
+  Sets the maximum compression level. The compression level affects CPU
+  usage during compression. This value affects CPU usage during compression.
+  Each session using compression initializes the compression algorithm with
+  this value. The default value is 1.
+
 tune.http.maxhdr <number>
   Sets the maximum number of headers in a request. When a request comes with a
   number of headers greater than this value (including the first line), it is
diff --git a/include/types/compression.h b/include/types/compression.h
index fa251f1..da356ad 100644
--- a/include/types/compression.h
+++ b/include/types/compression.h
@@ -44,6 +44,7 @@
 	void *zlib_pending_buf;
 	void *zlib_head;
 #endif /* USE_ZLIB */
+	int cur_lvl;
 };
 
 struct comp_algo {
diff --git a/include/types/global.h b/include/types/global.h
index e4e317b..cfb10d1 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -117,6 +117,7 @@
 		int zlibmemlevel;    /* zlib memlevel */
 		int zlibwindowsize;  /* zlib window size */
 #endif
+		int comp_maxlevel;    /* max HTTP compression level */
 	} tune;
 	struct {
 		char *prefix;           /* path prefix of unix bind socket */
diff --git a/src/cfgparse.c b/src/cfgparse.c
index d5ada1d..5f22b24 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -706,6 +706,22 @@
 		goto out;
 #endif
 	}
+	else if (!strcmp(args[0], "tune.comp.maxlevel")) {
+		if (*args[1]) {
+			global.tune.comp_maxlevel = atoi(args[1]);
+			if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) {
+				Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
+				      file, linenum, args[0]);
+				err_code |= ERR_ALERT | ERR_FATAL;
+				goto out;
+			}
+		} else {
+			Alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n",
+			      file, linenum, args[0]);
+			err_code |= ERR_ALERT | ERR_FATAL;
+			goto out;
+		}
+	}
 	else if (!strcmp(args[0], "uid")) {
 		if (global.uid != 0) {
 			Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
diff --git a/src/haproxy.c b/src/haproxy.c
index d0e740b..b322244 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -131,6 +131,7 @@
 		.zlibmemlevel = 8,
 		.zlibwindowsize = MAX_WBITS,
 #endif
+		.comp_maxlevel = 1,
 
 
 	},
diff --git a/src/proto_http.c b/src/proto_http.c
index 218e265..7f15107 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -2088,9 +2088,11 @@
 	ctx.idx = 0;
 
 	/* initialize compression */
-	if (s->comp_algo->init(&s->comp_ctx, 1) < 0)
+	if (s->comp_algo->init(&s->comp_ctx, global.tune.comp_maxlevel) < 0)
 		goto fail;
 
+	s->comp_ctx.cur_lvl = global.tune.comp_maxlevel;
+
 	/* remove Content-Length header */
 	if ((msg->flags & HTTP_MSGF_CNT_LEN) && http_find_header2("Content-Length", 14, res->p, &txn->hdr_idx, &ctx))
 		http_remove_header2(msg, &txn->hdr_idx, &ctx);