Commit 047d3195 authored by Geoff Simmons's avatar Geoff Simmons

Add the encoder mode parameter.

parent 895dcc8d
......@@ -68,8 +68,8 @@ XXX ...
.. _vmod_brotli.encoder:
new xencoder = brotli.encoder(STRING name, BYTES bufffer, INT quality, BOOL large_win, INT lgwin)
-------------------------------------------------------------------------------------------------
new xencoder = brotli.encoder(STRING name, BYTES bufffer, INT quality, BOOL large_win, INT lgwin, ENUM mode)
------------------------------------------------------------------------------------------------------------
::
......@@ -78,7 +78,8 @@ new xencoder = brotli.encoder(STRING name, BYTES bufffer, INT quality, BOOL larg
BYTES bufffer=32768,
INT quality=11,
BOOL large_win=0,
INT lgwin=22
INT lgwin=22,
ENUM {GENERIC, TEXT, FONT} mode=GENERIC
)
XXX ...
......
......@@ -3,7 +3,7 @@
varnishtest "test various custom parameter settings"
server s1 {
loop 7 {
loop 10 {
rxreq
txresp -body {Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.}
}
......@@ -166,6 +166,53 @@ varnish v1 -errvcl {vfp brotli failure: new err: lgwin 25 out of range (10 to 24
}
}
# mode
varnish v1 -vcl+backend {
import ${vmod_brotli};
sub vcl_init {
new mybr = brotli.encoder("br_generic", mode=GENERIC);
}
sub vcl_backend_response {
set beresp.filters = "br_generic unbr";
set beresp.uncacheable = true;
}
}
client c1 -run
varnish v1 -vcl+backend {
import ${vmod_brotli};
sub vcl_init {
new mybr = brotli.encoder("br_text", mode=TEXT);
}
sub vcl_backend_response {
set beresp.filters = "br_text unbr";
set beresp.uncacheable = true;
}
}
client c1 -run
varnish v1 -vcl+backend {
import ${vmod_brotli};
sub vcl_init {
new mybr = brotli.encoder("br_font", mode=FONT);
}
sub vcl_backend_response {
set beresp.filters = "br_font unbr";
set beresp.uncacheable = true;
}
}
client c1 -run
logexpect l1 -v v1 -d 1 -g vxid -q "VfpAcct" {
expect 0 * Begin bereq
expect * = VfpAcct {^unbr \d+ 269$}
......@@ -201,4 +248,19 @@ logexpect l1 -v v1 -d 1 -g vxid -q "VfpAcct" {
expect * = VfpAcct {^unbr \d+ 269$}
expect * = VfpAcct {^br_lg24 \d+ \d+$}
expect * = End
expect 0 * Begin bereq
expect * = VfpAcct {^unbr \d+ 269$}
expect * = VfpAcct {^br_generic \d+ \d+$}
expect * = End
expect 0 * Begin bereq
expect * = VfpAcct {^unbr \d+ 269$}
expect * = VfpAcct {^br_text \d+ \d+$}
expect * = End
expect 0 * Begin bereq
expect * = VfpAcct {^unbr \d+ 269$}
expect * = VfpAcct {^br_font \d+ \d+$}
expect * = End
} -run
......@@ -76,13 +76,14 @@ struct vbr {
};
struct vbr_settings {
unsigned magic;
#define VBR_SETTINGS_MAGIC 0xa61992aa
VCL_BYTES bufsz;
uint32_t quality;
uint32_t large_win;
uint32_t lgwin;
enum vbr_which which;
unsigned magic;
#define VBR_SETTINGS_MAGIC 0xa61992aa
VCL_BYTES bufsz;
uint32_t quality;
uint32_t large_win;
uint32_t lgwin;
enum BrotliEncoderMode mode;
enum vbr_which which;
};
struct vmod_brotli_encoder {
......@@ -162,11 +163,10 @@ setEncoderParams(struct vbr *vbr, const struct vbr_settings *settings)
assert(BrotliEncoderSetParameter(vbr->state.enc,
BROTLI_PARAM_LARGE_WINDOW,
settings->large_win) == BROTLI_TRUE);
if (settings->lgwin != 0)
assert(BrotliEncoderSetParameter(vbr->state.enc,
BROTLI_PARAM_LGWIN,
settings->lgwin)
== BROTLI_TRUE);
assert(BrotliEncoderSetParameter(vbr->state.enc, BROTLI_PARAM_LGWIN,
settings->lgwin) == BROTLI_TRUE);
assert(BrotliEncoderSetParameter(vbr->state.enc, BROTLI_PARAM_MODE,
settings->mode) == BROTLI_TRUE);
}
static void
......@@ -494,6 +494,7 @@ static struct vbr_settings default_encoder_settings = {
.quality = BROTLI_DEFAULT_QUALITY,
.large_win = 0,
.lgwin = BROTLI_DEFAULT_WINDOW,
.mode = BROTLI_DEFAULT_MODE,
.which = ENC,
};
......@@ -756,7 +757,7 @@ VCL_VOID
vmod_encoder__init(VRT_CTX, struct vmod_brotli_encoder **encp,
const char *vcl_name, struct vmod_priv *priv,
VCL_STRING filter_name, VCL_BYTES bufsz, VCL_INT quality,
VCL_BOOL large_win, VCL_INT lgwin)
VCL_BOOL large_win, VCL_INT lgwin, VCL_ENUM mode)
{
struct vmod_brotli_encoder *enc;
struct vfp *vfp = NULL;
......@@ -764,6 +765,7 @@ vmod_encoder__init(VRT_CTX, struct vmod_brotli_encoder **encp,
AN(encp);
AZ(*encp);
AN(mode);
if (quality < BROTLI_MIN_QUALITY || quality > BROTLI_MAX_QUALITY) {
VFAIL(ctx, "new %s: quality %ld out of range (%d to %d)",
......@@ -799,6 +801,22 @@ vmod_encoder__init(VRT_CTX, struct vmod_brotli_encoder **encp,
settings->quality = quality;
settings->large_win = large_win;
settings->lgwin = lgwin;
switch (mode[0]) {
case 'G':
assert(mode == enum_vmod_brotli_GENERIC);
settings->mode = BROTLI_MODE_GENERIC;
break;
case 'T':
assert(mode == enum_vmod_brotli_TEXT);
settings->mode = BROTLI_MODE_TEXT;
break;
case 'F':
assert(mode == enum_vmod_brotli_FONT);
settings->mode = BROTLI_MODE_FONT;
break;
default:
WRONG("illegal mode enum");
}
enc->vfp = vfp;
enc->vcl_name = strdup(vcl_name);
*encp = enc;
......
......@@ -63,7 +63,8 @@ algorithm for responses fetched from backends.
XXX ...
$Object encoder(PRIV_VCL, STRING name, BYTES bufffer=32768, INT quality=11,
BOOL large_win=0, INT lgwin=22)
BOOL large_win=0, INT lgwin=22,
ENUM {GENERIC, TEXT, FONT} mode=GENERIC)
XXX ...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment