MEDIUM: compression: add new "raw-deflate" compression algorithm
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.
diff --git a/doc/configuration.txt b/doc/configuration.txt
index e0aa485..1a89ad0 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -2251,19 +2251,28 @@
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.
+ 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.
+ 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.
- 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.
diff --git a/src/compression.c b/src/compression.c
index 8ddee57..cb06191 100644
--- a/src/compression.c
+++ b/src/compression.c
@@ -63,6 +63,7 @@
#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 @@
{ "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 @@
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 ****
***************************/