Commit f3af1ac6 by Geoff Simmons

Add the encoder quality parameter.

parent df105a52
......@@ -72,12 +72,16 @@ XXX ...
.. _vmod_brotli.encoder:
new xencoder = brotli.encoder(STRING name, BYTES bufffer)
---------------------------------------------------------
new xencoder = brotli.encoder(STRING name, BYTES bufffer, INT quality)
----------------------------------------------------------------------
::
new xencoder = brotli.encoder(STRING name, BYTES bufffer=32768)
new xencoder = brotli.encoder(
STRING name,
BYTES bufffer=32768,
INT quality=11
)
XXX ...
......
# looks like -*- vcl -*-
varnishtest "test various custom parameter settings"
server s1 {
loop 3 {
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.}
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Content-Encoding == <undef>
expect resp.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.}
}
# Encoder quality
varnish v1 -arg "-p vsl_mask=+VfpAcct" -vcl+backend {
import ${vmod_brotli};
sub vcl_init {
new mybr = brotli.encoder("br_q0", quality=0);
}
sub vcl_backend_response {
set beresp.filters = "br_q0 unbr";
set beresp.uncacheable = true;
}
} -start
client c1 -run
varnish v1 -vcl+backend {
import ${vmod_brotli};
sub vcl_init {
new mybr = brotli.encoder("br_q5", quality=5);
}
sub vcl_backend_response {
set beresp.filters = "br_q5 unbr";
set beresp.uncacheable = true;
}
}
client c1 -run
varnish v1 -vcl+backend {
import ${vmod_brotli};
sub vcl_init {
new mybr = brotli.encoder("br_q11", quality=11);
}
sub vcl_backend_response {
set beresp.filters = "br_q11 unbr";
set beresp.uncacheable = true;
}
}
client c1 -run
varnish v1 -errvcl {vfp brotli failure: new err: quality -1 out of range (0 to 11)} {
import ${vmod_brotli};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new err = brotli.encoder("b", quality=-1);
}
}
varnish v1 -errvcl {vfp brotli failure: new err: quality 12 out of range (0 to 11)} {
import ${vmod_brotli};
backend b { .host = "${bad_ip}"; }
sub vcl_init {
new err = brotli.encoder("b", quality=12);
}
}
logexpect l1 -v v1 -d 1 -g vxid -q "VfpAcct" {
expect 0 * Begin bereq
expect * = VfpAcct {^unbr \d+ 269$}
expect * = VfpAcct {^br_q0 \d+ \d+$}
expect * = End
expect 0 * Begin bereq
expect * = VfpAcct {^unbr \d+ 269$}
expect * = VfpAcct {^br_q5 \d+ \d+$}
expect * = End
expect 0 * Begin bereq
expect * = VfpAcct {^unbr \d+ 269$}
expect * = VfpAcct {^br_q11 \d+ \d+$}
expect * = End
} -run
......@@ -77,6 +77,7 @@ struct vbr_settings {
unsigned magic;
#define VBR_SETTINGS_MAGIC 0xa61992aa
VCL_BYTES bufsz;
uint32_t quality;
enum vbr_which which;
};
......@@ -120,7 +121,6 @@ newVBR(enum vbr_which which)
if (vbr->state.dec == NULL)
return (NULL);
}
/* XXX configure the handle */
vbr->which = which;
return (vbr);
}
......@@ -142,10 +142,36 @@ destroy(struct vbr **vp)
FREE_OBJ(vbr);
}
static void
setEncoderParams(struct vbr *vbr, const struct vbr_settings *settings)
{
CHECK_OBJ_NOTNULL(settings, VBR_SETTINGS_MAGIC);
assert(BrotliEncoderSetParameter(vbr->state.enc, BROTLI_PARAM_QUALITY,
settings->quality) == BROTLI_TRUE);
}
static void
setDecoderParams(struct vbr *vbr, const struct vbr_settings *settings)
{
(void) vbr;
(void) settings;
}
static inline void
setParams(struct vbr *vbr, const struct vbr_settings *settings)
{
CHECK_OBJ_NOTNULL(vbr, VBR_MAGIC);
if (vbr->which == ENC)
setEncoderParams(vbr, settings);
else
setDecoderParams(vbr, settings);
}
static int
getBuf(struct vbr *vbr, const struct vbr_settings *settings)
{
CHECK_OBJ_NOTNULL(vbr, VBR_MAGIC);
CHECK_OBJ_NOTNULL(settings, VBR_SETTINGS_MAGIC);
AZ(vbr->bufsz);
AZ(vbr->buflen);
AZ(vbr->buf);
......@@ -277,6 +303,7 @@ vfp_br_init(struct vfp_ctx *ctx, struct vfp_entry *ent)
ent->priv1 = vbr;
if (getBuf(vbr, settings))
return (VFP_ERROR);
setParams(vbr, settings);
setInputBuf(vbr, vbr->buf, 0);
AZ(vbr->buflen);
......@@ -588,7 +615,7 @@ coder_init(VRT_CTX, const char *vcl_name, struct vmod_priv *priv,
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_STRING filter_name, VCL_BYTES bufsz, VCL_INT quality)
{
struct vmod_brotli_encoder *enc;
struct vfp *vfp = NULL;
......@@ -597,6 +624,13 @@ vmod_encoder__init(VRT_CTX, struct vmod_brotli_encoder **encp,
AN(encp);
AZ(*encp);
if (quality < BROTLI_MIN_QUALITY || quality > BROTLI_MAX_QUALITY) {
VFAIL(ctx, "new %s: quality %ld out of range (%d to %d)",
vcl_name, quality, BROTLI_MIN_QUALITY,
BROTLI_MAX_QUALITY);
return;
}
if (coder_init(ctx, vcl_name, priv, filter_name, bufsz, &vfp,
&settings) != 0)
return;
......@@ -614,6 +648,7 @@ vmod_encoder__init(VRT_CTX, struct vmod_brotli_encoder **encp,
vfp->pull = vfp_br_pull;
VRT_AddVFP(ctx, vfp);
settings->which = ENC;
settings->quality = quality;
enc->vfp = vfp;
}
......
......@@ -66,7 +66,7 @@ algorithm for responses fetched from backends.
XXX ...
$Object encoder(PRIV_VCL, STRING name, BYTES bufffer=32768)
$Object encoder(PRIV_VCL, STRING name, BYTES bufffer=32768, INT quality=11)
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