[master] 704a87000 Engage the resp.filters variable
Poul-Henning Kamp
phk at FreeBSD.org
Mon Nov 19 22:15:16 UTC 2018
commit 704a87000bb2acdf3e923f6560fd0b99965e6c1f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Nov 19 22:03:12 2018 +0000
Engage the resp.filters variable
diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c
index 37e4d84e7..c59fe857f 100644
--- a/bin/varnishd/cache/cache_range.c
+++ b/bin/varnishd/cache/cache_range.c
@@ -205,17 +205,9 @@ vrg_range_init(struct req *req, void **priv)
return (1);
}
-static const struct vdp vrg_vdp = {
+const struct vdp VDP_range = {
.name = "range",
.init = vrg_range_init,
.bytes = vrg_range_bytes,
.fini = vrg_range_fini,
};
-
-void
-VRG_dorange(struct req *req, const char *r)
-{
-
- (void)r;
- AZ(VDP_Push(req, &vrg_vdp, NULL));
-}
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 0b4141606..ae807f739 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -339,9 +339,8 @@ static enum req_fsm_nxt
cnt_transmit(struct worker *wrk, struct req *req)
{
struct boc *boc;
- const char *r;
uint16_t status;
- int err, sendbody, head;
+ int sendbody, head;
intmax_t clval;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -357,7 +356,6 @@ cnt_transmit(struct worker *wrk, struct req *req)
/* RFC 7230, 3.3.3 */
status = http_GetStatus(req->resp);
head = !strcmp(req->http0->hd[HTTP_HDR_METHOD].b, "HEAD");
- err = 0;
if (boc != NULL)
req->resp_len = clval;
@@ -371,27 +369,16 @@ cnt_transmit(struct worker *wrk, struct req *req)
sendbody = 1;
}
- if (!req->disable_esi && req->resp_len != 0 &&
- ObjHasAttr(wrk, req->objcore, OA_ESIDATA) &&
- VDP_Push(req, &VDP_esi, NULL) < 0)
- err++;
-
- if (cache_param->http_gzip_support &&
- ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED) &&
- !RFC2616_Req_Gzip(req->http) &&
- VDP_Push(req, &VDP_gunzip, NULL) < 0)
- err++;
-
- if (cache_param->http_range_support && status == 200) {
- http_ForceHeader(req->resp, H_Accept_Ranges, "bytes");
- if (http_GetHdr(req->http, H_Range, &r))
- VRG_dorange(req, r);
- }
-
- if (err) {
+ if (req->filter_list == NULL)
+ req->filter_list = resp_Get_Filter_List(req);
+ if (req->filter_list == NULL ||
+ VCL_StackVDP(req, req->vcl, req->filter_list)) {
VSLb(req->vsl, SLT_Error, "Failure to push processors");
req->doclose = SC_OVERLOAD;
} else {
+ if (cache_param->http_range_support && status == 200)
+ http_ForceHeader(req->resp, H_Accept_Ranges, "bytes");
+
if (status < 200 || status == 204) {
// rfc7230,l,1691,1695
http_Unset(req->resp, H_Content_Length);
@@ -417,8 +404,8 @@ cnt_transmit(struct worker *wrk, struct req *req)
}
if (req->resp_len == 0)
sendbody = 0;
- req->transport->deliver(req, boc, sendbody);
}
+ req->transport->deliver(req, boc, sendbody);
VSLb_ts_req(req, "Resp", W_TIM_real(wrk));
@@ -438,6 +425,7 @@ cnt_transmit(struct worker *wrk, struct req *req)
(void)HSH_DerefObjCore(wrk, &req->objcore, HSH_RUSH_POLICY);
http_Teardown(req->resp);
+ req->filter_list = NULL;
req->res_mode = 0;
return (REQ_FSM_DONE);
}
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 791fa30b8..08caa721b 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -188,6 +188,7 @@ int VDP_DeliverObj(struct req *req);
extern const struct vdp VDP_gunzip;
extern const struct vdp VDP_esi;
+extern const struct vdp VDP_range;
/* cache_expire.c */
void EXP_Init(void);
@@ -290,8 +291,6 @@ typedef void obj_event_f(struct worker *, void *priv, struct objcore *,
uintptr_t ObjSubscribeEvents(obj_event_f *, void *, unsigned mask);
void ObjUnsubscribeEvents(uintptr_t *);
-
-
/* cache_panic.c */
void PAN_Init(void);
int PAN_already(struct vsb *, const void *);
@@ -308,9 +307,6 @@ int Pool_TrySumstat(const struct worker *wrk);
void Pool_PurgeStat(unsigned nobj);
int Pool_Task_Any(struct pool_task *task, enum task_prio prio);
-/* cache_range.c [VRG] */
-void VRG_dorange(struct req *req, const char *r);
-
/* cache_req.c */
struct req *Req_New(const struct worker *, struct sess *);
void Req_Release(struct req *);
@@ -405,11 +401,15 @@ int VCL_IterDirector(struct cli *, const char *, vcl_be_func *, void *);
/* cache_vcl_vrt.c */
void VCL_VRT_Init(void);
-int VCL_StackVFP(struct vfp_ctx *, const struct vcl *, const char *);
/* cache_vrt.c */
void pan_privs(struct vsb *, const struct vrt_privs *);
+/* cache_vrt_filter.c */
+int VCL_StackVFP(struct vfp_ctx *, const struct vcl *, const char *);
+int VCL_StackVDP(struct req *, const struct vcl *, const char *);
+const char *resp_Get_Filter_List(struct req *req);
+
/* cache_vrt_priv.c */
extern struct vrt_privs cli_task_privs[1];
diff --git a/bin/varnishd/cache/cache_vrt_filter.c b/bin/varnishd/cache/cache_vrt_filter.c
index b74ceb318..82540cc0d 100644
--- a/bin/varnishd/cache/cache_vrt_filter.c
+++ b/bin/varnishd/cache/cache_vrt_filter.c
@@ -190,6 +190,7 @@ VCL_StackVFP(struct vfp_ctx *vc, const struct vcl *vcl, const char *fl)
{
const struct vfilter *vp;
+ AN(fl);
VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl);
while (1) {
@@ -203,6 +204,27 @@ VCL_StackVFP(struct vfp_ctx *vc, const struct vcl *vcl, const char *fl)
}
}
+int
+VCL_StackVDP(struct req *req, const struct vcl *vcl, const char *fl)
+{
+ const struct vfilter *vp;
+
+ AN(fl);
+ VSLb(req->vsl, SLT_Filters, "%s", fl);
+ while (1) {
+ vp = vcl_filter_list_iter(&vdp_filters, &vcl->vfps, &fl);
+ if (vp == NULL)
+ return (0);
+ if (vp == vfilter_error) {
+ VSLb(req->vsl, SLT_Error,
+ "Filter '...%s' not found", fl);
+ return (-1);
+ }
+ if (VDP_Push(req, vp->vdp, NULL))
+ return (-1);
+ }
+}
+
void
VCL_VRT_Init(void)
{
@@ -213,15 +235,16 @@ VCL_VRT_Init(void)
VRT_AddVFP(NULL, &VFP_esi_gzip);
VRT_AddVDP(NULL, &VDP_esi);
VRT_AddVDP(NULL, &VDP_gunzip);
+ VRT_AddVDP(NULL, &VDP_range);
}
/*--------------------------------------------------------------------
*/
-typedef void filter_list_t(const void *, struct vsb *vsb);
+typedef void filter_list_t(void *, struct vsb *vsb);
static const char *
-filter_on_ws(struct ws *ws, filter_list_t *func, const void *arg)
+filter_on_ws(struct ws *ws, filter_list_t *func, void *arg)
{
unsigned u;
struct vsb vsb[1];
@@ -253,7 +276,7 @@ filter_on_ws(struct ws *ws, filter_list_t *func, const void *arg)
*/
static void v_matchproto_(filter_list_t)
-vbf_default_filter_list(const void *arg, struct vsb *vsb)
+vbf_default_filter_list(void *arg, struct vsb *vsb)
{
const struct busyobj *bo;
const char *p;
@@ -328,15 +351,29 @@ VBF_Get_Filter_List(struct busyobj *bo)
*/
static void v_matchproto_(filter_list_t)
-resp_default_filter_list(const void *arg, struct vsb *vsb)
+resp_default_filter_list(void *arg, struct vsb *vsb)
{
- const struct req *req;
+ struct req *req;
+ const char *r;
CAST_OBJ_NOTNULL(req, arg, REQ_MAGIC);
- (void)vsb;
+
+ if (!req->disable_esi && req->resp_len != 0 &&
+ ObjHasAttr(req->wrk, req->objcore, OA_ESIDATA))
+ VSB_cat(vsb, " esi");
+
+ if (cache_param->http_gzip_support &&
+ ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED) &&
+ !RFC2616_Req_Gzip(req->http))
+ VSB_cat(vsb, " gunzip");
+
+ if (cache_param->http_range_support &&
+ http_GetStatus(req->resp) == 200 &&
+ http_GetHdr(req->http, H_Range, &r))
+ VSB_cat(vsb, " range");
}
-static const char *
+const char *
resp_Get_Filter_List(struct req *req)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
diff --git a/bin/varnishtest/tests/c00071.vtc b/bin/varnishtest/tests/c00071.vtc
index 6cff35d87..7e3c156ee 100644
--- a/bin/varnishtest/tests/c00071.vtc
+++ b/bin/varnishtest/tests/c00071.vtc
@@ -39,6 +39,8 @@ client c1 {
expect resp.http.x-of == <undef>
} -run
+varnish v1 -vsl_catchup
+
client c2 {
txreq -url /baz
rxresp
diff --git a/bin/varnishtest/tests/g00003.vtc b/bin/varnishtest/tests/g00003.vtc
index 773917cba..34744bb98 100644
--- a/bin/varnishtest/tests/g00003.vtc
+++ b/bin/varnishtest/tests/g00003.vtc
@@ -48,7 +48,6 @@ varnish v1 -cliok "param.set http_gzip_support true" -vcl+backend {
}
sub vcl_deliver {
set resp.http.filters = resp.filters;
- set resp.filters = "";
}
} -start
@@ -57,18 +56,30 @@ client c1 {
rxresp
expect resp.http.content-encoding == <undef>
expect resp.bodylen == 41
+} -run
+
+varnish v1 -vsl_catchup
+client c1 {
txreq -url /bar -hdr "Accept-Encoding: gzip"
rxresp
expect resp.http.content-encoding == <undef>
expect resp.bodylen == 42
+} -run
+
+varnish v1 -vsl_catchup
+client c1 {
txreq -url /foobar -hdr "Accept-Encoding: gzip"
rxresp
expect resp.http.content-encoding == "gzip"
gunzip
expect resp.bodylen == 43
+} -run
+varnish v1 -vsl_catchup
+
+client c1 {
txreq -url /foobar
rxresp
expect resp.http.content-encoding == <undef>
More information about the varnish-commit
mailing list