From: Willy Tarreau Date: Sat, 28 Mar 2015 16:00:39 +0000 (+0100) Subject: MEDIUM: compression: add new "raw-deflate" compression algorithm X-Git-Tag: v1.6-dev2~293 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c91840aa3374548f07029eb3f985f3016ce7f713;p=thirdparty%2Fhaproxy.git 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 e0aa485abb..1a89ad0a9f 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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. diff --git a/src/compression.c b/src/compression.c index 8ddee57bd9..cb061919d3 100644 --- a/src/compression.c +++ b/src/compression.c @@ -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 **** ***************************/