mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-29 06:40:59 +01:00
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.
This commit is contained in:
parent
615105e7e8
commit
c91840aa33
@ -2258,12 +2258,21 @@ compression offload
|
|||||||
gzip applies gzip compression. This setting is only available when
|
gzip applies gzip compression. This setting is only available when
|
||||||
support for zlib was built in.
|
support for zlib was built in.
|
||||||
|
|
||||||
deflate same as gzip, but with deflate algorithm and zlib format.
|
deflate same as "gzip", but with deflate algorithm and zlib format.
|
||||||
Note that this algorithm has ambiguous support on many browsers
|
Note that this algorithm has ambiguous support on many
|
||||||
and no support at all from recent ones. It is strongly
|
browsers and no support at all from recent ones. It is
|
||||||
recommended not to use it for anything else than experimentation.
|
strongly recommended not to use it for anything else than
|
||||||
This setting is only available when support for zlib was built
|
experimentation. This setting is only available when support
|
||||||
in.
|
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
|
Compression will be activated depending on the Accept-Encoding request
|
||||||
header. With identity, it does not take care of that header.
|
header. With identity, it does not take care of that header.
|
||||||
|
|||||||
@ -63,6 +63,7 @@ static int identity_end(struct comp_ctx **comp_ctx);
|
|||||||
|
|
||||||
#ifdef USE_ZLIB
|
#ifdef USE_ZLIB
|
||||||
static int gzip_init(struct comp_ctx **comp_ctx, int level);
|
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_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_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);
|
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 },
|
{ "identity", 8, "identity", 8, identity_init, identity_add_data, identity_flush, identity_reset, identity_end },
|
||||||
#ifdef USE_ZLIB
|
#ifdef USE_ZLIB
|
||||||
{ "deflate", 7, "deflate", 7, deflate_init, deflate_add_data, deflate_flush, deflate_reset, deflate_end },
|
{ "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 },
|
{ "gzip", 4, "gzip", 4, gzip_init, deflate_add_data, deflate_flush, deflate_reset, deflate_end },
|
||||||
#endif /* USE_ZLIB */
|
#endif /* USE_ZLIB */
|
||||||
{ NULL, 0, NULL, 0, NULL , NULL, NULL, NULL, NULL }
|
{ 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;
|
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 ****
|
**** Deflate algorithm ****
|
||||||
***************************/
|
***************************/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user