]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: compression: add new "raw-deflate" compression algorithm
authorWilly Tarreau <w@1wt.eu>
Sat, 28 Mar 2015 16:00:39 +0000 (17:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 28 Mar 2015 16:01:30 +0000 (17:01 +0100)
This algorithm is exactly the same as "deflate" without the zlib wrapper,
and used as an alternative when the browser wants "deflate". All major
browsers understand it and despite violating the standards, it is known
to work better than "deflate", at least on MSIE and some versions of
Safari. Do not use it in conjunction with "deflate", use either one or
the other since both react to the same Accept-Encoding token. Note that
the lack of Adler32 checksum makes it slightly faster.

doc/configuration.txt
src/compression.c

index e0aa485abb64d3a0edac1512d796e800f6a1a140..1a89ad0a9f0303c8ab361022ca43ae5aa1f94c3e 100644 (file)
@@ -2251,19 +2251,28 @@ compression offload
     offload  makes haproxy work as a compression offloader only (see notes).
 
   The currently supported algorithms are :
-    identity  this is mostly for debugging, and it was useful for developing
-              the compression feature. Identity does not apply any change on
-              data.
-
-    gzip      applies gzip compression. This setting is only available when
-              support for zlib was built in.
-
-    deflate   same as gzip, but with deflate algorithm and zlib format.
-              Note that this algorithm has ambiguous support on many browsers
-              and no support at all from recent ones. It is strongly
-              recommended not to use it for anything else than experimentation.
-              This setting is only available when support for zlib was built
-              in.
+    identity     this is mostly for debugging, and it was useful for developing
+                 the compression feature. Identity does not apply any change on
+                 data.
+
+    gzip         applies gzip compression. This setting is only available when
+                 support for zlib was built in.
+
+    deflate      same as "gzip", but with deflate algorithm and zlib format.
+                 Note that this algorithm has ambiguous support on many
+                 browsers and no support at all from recent ones. It is
+                 strongly recommended not to use it for anything else than
+                 experimentation. This setting is only available when support
+                 for zlib was built in.
+
+    raw-deflate  same as "deflate" without the zlib wrapper, and used as an
+                 alternative when the browser wants "deflate". All major
+                 browsers understand it and despite violating the standards,
+                 it is known to work better than "deflate", at least on MSIE
+                 and some versions of Safari. Do not use it in conjunction
+                 with "deflate", use either one or the other since both react
+                 to the same Accept-Encoding token. This setting is only
+                 available when support for zlib was built in.
 
   Compression will be activated depending on the Accept-Encoding request
   header. With identity, it does not take care of that header.
index 8ddee57bd92b8930facb9130c1e07dcfddda9f61..cb061919d3a79c713afdc8c6b83a8b23a3f201f6 100644 (file)
@@ -63,6 +63,7 @@ static int identity_end(struct comp_ctx **comp_ctx);
 
 #ifdef USE_ZLIB
 static int gzip_init(struct comp_ctx **comp_ctx, int level);
+static int raw_def_init(struct comp_ctx **comp_ctx, int level);
 static int deflate_init(struct comp_ctx **comp_ctx, int level);
 static int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out);
 static int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
@@ -76,6 +77,7 @@ const struct comp_algo comp_algos[] =
        { "identity",     8, "identity", 8, identity_init, identity_add_data, identity_flush, identity_reset, identity_end },
 #ifdef USE_ZLIB
        { "deflate",      7, "deflate",  7, deflate_init,  deflate_add_data,  deflate_flush,  deflate_reset,  deflate_end },
+       { "raw-deflate", 11, "deflate",  7, raw_def_init,  deflate_add_data,  deflate_flush,  deflate_reset,  deflate_end },
        { "gzip",         4, "gzip",     4, gzip_init,     deflate_add_data,  deflate_flush,  deflate_reset,  deflate_end },
 #endif /* USE_ZLIB */
        { NULL,       0, NULL,          0, NULL ,         NULL,              NULL,           NULL,           NULL }
@@ -539,6 +541,26 @@ static int gzip_init(struct comp_ctx **comp_ctx, int level)
 
        return 0;
 }
+
+/* Raw deflate algorithm */
+static int raw_def_init(struct comp_ctx **comp_ctx, int level)
+{
+       z_stream *strm;
+
+       if (init_comp_ctx(comp_ctx) < 0)
+               return -1;
+
+       strm = &(*comp_ctx)->strm;
+
+       if (deflateInit2(strm, level, Z_DEFLATED, -global.tune.zlibwindowsize, global.tune.zlibmemlevel, Z_DEFAULT_STRATEGY) != Z_OK) {
+               deinit_comp_ctx(comp_ctx);
+               return -1;
+       }
+
+       (*comp_ctx)->cur_lvl = level;
+       return 0;
+}
+
 /**************************
 **** Deflate algorithm ****
 ***************************/