Hi,
As discussed on irc the attached diff adds a new counter, n_gunzip_test, to
decouple the existing counter from testing and actually uncompressing at
delivering time.
Not terribly thrilled about the diff but I've tried a few variations and I
liked this best.
Comments? OKs?
PS: pedantic question of the day: shouldn't all these be ungzip and not
gunzip?
bin/varnishd/cache/cache.h | 1 +
bin/varnishd/cache/cache_gzip.c | 26 ++++++++++++++++++++++----
bin/varnishtest/tests/g00007.vtc | 32 ++++++++++++++++++++++++++++++++
include/tbl/vsc_f_main.h | 4 ++++
4 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 9ff55f6..7672eeb 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -927,6 +927,7 @@ enum vgzret_e {
enum vgz_flag { VGZ_NORMAL, VGZ_ALIGN, VGZ_RESET, VGZ_FINISH };
struct vgz *VGZ_NewUngzip(struct vsl_log *vsl, const char *id);
+struct vgz *VGZ_NewUngzipTest(struct vsl_log *vsl, const char *id);
struct vgz *VGZ_NewGzip(struct vsl_log *vsl, const char *id);
void VGZ_Ibuf(struct vgz *, const void *, ssize_t len);
int VGZ_IbufEmpty(const struct vgz *vg);
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 8cafe6b..7c0e5c2 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -79,14 +79,13 @@ vgz_alloc_vgz(struct vsl_log *vsl, const char *id)
return (vg);
}
-struct vgz *
-VGZ_NewUngzip(struct vsl_log *vsl, const char *id)
+static struct vgz *
+vgz_new_ungzip(struct vsl_log *vsl, const char *id)
{
struct vgz *vg;
vg = vgz_alloc_vgz(vsl, id);
vg->dir = VGZ_UN;
- VSC_C_main->n_gunzip++;
/*
* Max memory usage according to zonf.h:
@@ -99,6 +98,22 @@ VGZ_NewUngzip(struct vsl_log *vsl, const char *id)
}
struct vgz *
+VGZ_NewUngzip(struct vsl_log *vsl, const char *id)
+{
+ VSC_C_main->n_gunzip++;
+
+ return (vgz_new_ungzip(vsl, id));
+}
+
+struct vgz *
+VGZ_NewUngzipTest(struct vsl_log *vsl, const char *id)
+{
+ VSC_C_main->n_gunzip_test++;
+
+ return (vgz_new_ungzip(vsl, id));
+}
+
+struct vgz *
VGZ_NewGzip(struct vsl_log *vsl, const char *id)
{
struct vgz *vg;
@@ -473,7 +488,10 @@ vfp_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe)
} else {
if (!http_HdrIs(vc->http, H_Content_Encoding, "gzip"))
return (VFP_NULL);
- vg = VGZ_NewUngzip(vc->vsl, vfe->vfp->priv1);
+ if (vfe->vfp->priv2 == VFP_GUNZIP)
+ vg = VGZ_NewUngzip(vc->vsl, vfe->vfp->priv1);
+ else
+ vg = VGZ_NewUngzipTest(vc->vsl, vfe->vfp->priv1);
}
if (vg == NULL)
return (VFP_ERROR);
diff --git a/bin/varnishtest/tests/g00007.vtc b/bin/varnishtest/tests/g00007.vtc
new file mode 100644
index 0000000..09d4d87
--- /dev/null
+++ b/bin/varnishtest/tests/g00007.vtc
@@ -0,0 +1,32 @@
+varnishtest "Test gzip/gunzip counters"
+
+server s1 {
+ rxreq
+ txresp -gzipbody "foo"
+ rxreq
+ txresp -body "bar"
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_backend_response {
+ if (bereq.url ~ "bar") {
+ set beresp.do_gzip = true;
+ }
+ }
+} -start
+
+client c1 {
+ txreq
+ rxresp
+ expect resp.body == "foo"
+ txreq -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.bodylen == 26
+ txreq -url /bar
+ rxresp
+ expect resp.body == "bar"
+} -run
+
+varnish v1 -expect n_gzip == 1
+varnish v1 -expect n_gunzip == 2
+varnish v1 -expect n_gunzip_test == 1
diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h
index 845fbcb..c0e1372 100644
--- a/include/tbl/vsc_f_main.h
+++ b/include/tbl/vsc_f_main.h
@@ -647,6 +647,10 @@ VSC_F(n_gunzip, uint64_t, 0, 'a', info,
"Gunzip operations",
""
)
+VSC_F(n_gunzip_test, uint64_t, 0, 'a', info,
+ "Gunzip test operations",
+ ""
+)
/*--------------------------------------------------------------------*/
_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev