[master] 8d04330 Add SLT_Filters, shuffle code more naturally.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Apr 18 07:56:11 UTC 2018
commit 8d043303bf1ffaa1e7120e1bf733d0738dc51642
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Apr 18 07:17:56 2018 +0000
Add SLT_Filters, shuffle code more naturally.
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 424ccbc..1706c98 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -36,7 +36,6 @@
#include "hash/hash_slinger.h"
#include "storage/storage.h"
#include "vcl.h"
-#include "vct.h"
#include "vtim.h"
/*--------------------------------------------------------------------
@@ -504,10 +503,10 @@ vbf_stp_fetchbody(struct worker *wrk, struct busyobj *bo)
static void
vbf_default_filter_list(const struct busyobj *bo, struct vsb *vsb)
{
-
+ const char *p;
int do_gzip = bo->do_gzip;
int do_gunzip = bo->do_gunzip;
- int is_gzip, is_gunzip;
+ int is_gzip = 0, is_gunzip = 0;
/*
* The VCL variables beresp.do_g[un]zip tells us how we want the
@@ -528,9 +527,10 @@ vbf_default_filter_list(const struct busyobj *bo, struct vsb *vsb)
if (!cache_param->http_gzip_support)
do_gzip = do_gunzip = 0;
- is_gzip = http_HdrIs(bo->beresp, H_Content_Encoding, "gzip");
- is_gunzip = !http_GetHdr(bo->beresp, H_Content_Encoding, NULL);
- assert(is_gzip == 0 || is_gunzip == 0);
+ if (http_GetHdr(bo->beresp, H_Content_Encoding, &p))
+ is_gzip = !strcasecmp(p, "gzip");
+ else
+ is_gunzip = 1;
/* We won't gunzip unless it is gzip'ed */
if (do_gunzip && !is_gzip)
@@ -563,7 +563,6 @@ vbf_default_filter_list(const struct busyobj *bo, struct vsb *vsb)
VSB_cat(vsb, " testgunzip");
}
-
const char *
VBF_Get_Filter_List(struct busyobj *bo)
{
@@ -587,60 +586,6 @@ VBF_Get_Filter_List(struct busyobj *bo)
return (VSB_data(vsb) + 1);
}
-static const struct vfp *vfplist[] = {
- &VFP_testgunzip,
- &VFP_gunzip,
- &VFP_gzip,
- &VFP_esi,
- &VFP_esi_gzip,
- NULL,
-};
-
-static int
-vbf_figure_out_vfp(struct busyobj *bo)
-{
- const char *p, *q;
- const struct vfp **vp;
- int l;
-
- /* No body -> done */
- if (bo->htc->body_status == BS_NONE || bo->htc->content_length == 0) {
- http_Unset(bo->beresp, H_Content_Encoding);
- bo->do_gzip = bo->do_gunzip = 0;
- bo->do_stream = 0;
- bo->filter_list = "";
- return (0);
- }
-
- if (bo->filter_list == NULL)
- bo->filter_list = VBF_Get_Filter_List(bo);
-
- VSLb(bo->vsl, SLT_Debug, "Filters <%s>", bo->filter_list);
-
- for (p = bo->filter_list; *p; p = q) {
- if (vct_isspace(*p)) {
- q = p + 1;
- continue;
- }
- for (q = p; *q; q++)
- if (vct_isspace(*q))
- break;
- for(vp = vfplist; *vp != NULL; vp++) {
- l = strlen((*vp)->name);
- if (l != q - p)
- continue;
- if (!memcmp(p, (*vp)->name, l))
- break;
- }
- if (*vp == NULL)
- return (VFP_Error(bo->vfc,
- "Filter '%.*s' not found", (int)(q-p), p));
- if (VFP_Push(bo->vfc, *vp) == NULL)
- return (-1);
- }
- return (0);
-}
-
static enum fetch_step
vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
{
@@ -652,7 +597,17 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
assert(wrk->handling == VCL_RET_DELIVER);
- if (vbf_figure_out_vfp(bo)) {
+ /* No body -> done */
+ if (bo->htc->body_status == BS_NONE || bo->htc->content_length == 0) {
+ http_Unset(bo->beresp, H_Content_Encoding);
+ bo->do_gzip = bo->do_gunzip = 0;
+ bo->do_stream = 0;
+ bo->filter_list = "";
+ } else if (bo->filter_list == NULL) {
+ bo->filter_list = VBF_Get_Filter_List(bo);
+ }
+
+ if (VFP_FilterList(bo->vfc, bo->filter_list)) {
(bo)->htc->doclose = SC_OVERLOAD;
VDI_Finish((bo)->wrk, bo);
return (F_STP_ERROR);
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index 1413f1b..667c713 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -35,6 +35,8 @@
#include "cache_filter.h"
#include "vcli_serve.h"
+#include "vct.h"
+
static unsigned fetchfrag;
/*--------------------------------------------------------------------
@@ -198,6 +200,7 @@ VFP_Suck(struct vfp_ctx *vc, void *p, ssize_t *lp)
/*--------------------------------------------------------------------
*/
+
struct vfp_entry *
VFP_Push(struct vfp_ctx *vc, const struct vfp *vfp)
{
@@ -221,6 +224,52 @@ VFP_Push(struct vfp_ctx *vc, const struct vfp *vfp)
}
/*--------------------------------------------------------------------
+ */
+
+static const struct vfp *vfplist[] = {
+ &VFP_testgunzip,
+ &VFP_gunzip,
+ &VFP_gzip,
+ &VFP_esi,
+ &VFP_esi_gzip,
+ NULL,
+};
+
+int
+VFP_FilterList(struct vfp_ctx *vc, const char *fl)
+{
+ const char *p, *q;
+ const struct vfp **vp;
+ int l;
+
+ VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl);
+
+ for (p = fl; *p; p = q) {
+ if (vct_isspace(*p)) {
+ q = p + 1;
+ continue;
+ }
+ for (q = p; *q; q++)
+ if (vct_isspace(*q))
+ break;
+ for(vp = vfplist; *vp != NULL; vp++) {
+ l = strlen((*vp)->name);
+ if (l != q - p)
+ continue;
+ if (!memcmp(p, (*vp)->name, l))
+ break;
+ }
+ if (*vp == NULL)
+ return (VFP_Error(vc,
+ "Filter '%.*s' not found", (int)(q-p), p));
+ if (VFP_Push(vc, *vp) == NULL)
+ return (-1);
+ }
+ return (0);
+}
+
+
+/*--------------------------------------------------------------------
* Debugging aids
*/
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
index f6dae16..789a68c 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -88,6 +88,7 @@ struct vfp_ctx {
enum vfp_status VFP_Suck(struct vfp_ctx *, void *p, ssize_t *lp);
enum vfp_status VFP_Error(struct vfp_ctx *, const char *fmt, ...)
v_printflike_(2, 3);
+int VFP_FilterList(struct vfp_ctx *, const char *);
/* Deliver processors ------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 5e56b3a..0ab6286 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -927,4 +927,3 @@ VRT_r_beresp_filters(VRT_CTX)
/* We do not set bo->filter_list yet, things might still change */
return (VBF_Get_Filter_List(ctx->bo));
}
-
diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h
index 89a422a..88106bc 100644
--- a/include/tbl/vsl_tags.h
+++ b/include/tbl/vsl_tags.h
@@ -573,6 +573,10 @@ SLTM(HitMiss, 0, "Hit for miss object in cache.",
"\n"
)
+SLTM(Filters, 0, "Body filters",
+ "List of filters applied to the body"
+)
+
#undef NODEF_NOTICE
#undef SLTM
More information about the varnish-commit
mailing list