Commit 704a8700 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Engage the resp.filters variable

parent 45c767cc
...@@ -205,17 +205,9 @@ vrg_range_init(struct req *req, void **priv) ...@@ -205,17 +205,9 @@ vrg_range_init(struct req *req, void **priv)
return (1); return (1);
} }
static const struct vdp vrg_vdp = { const struct vdp VDP_range = {
.name = "range", .name = "range",
.init = vrg_range_init, .init = vrg_range_init,
.bytes = vrg_range_bytes, .bytes = vrg_range_bytes,
.fini = vrg_range_fini, .fini = vrg_range_fini,
}; };
void
VRG_dorange(struct req *req, const char *r)
{
(void)r;
AZ(VDP_Push(req, &vrg_vdp, NULL));
}
...@@ -339,9 +339,8 @@ static enum req_fsm_nxt ...@@ -339,9 +339,8 @@ static enum req_fsm_nxt
cnt_transmit(struct worker *wrk, struct req *req) cnt_transmit(struct worker *wrk, struct req *req)
{ {
struct boc *boc; struct boc *boc;
const char *r;
uint16_t status; uint16_t status;
int err, sendbody, head; int sendbody, head;
intmax_t clval; intmax_t clval;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
...@@ -357,7 +356,6 @@ cnt_transmit(struct worker *wrk, struct req *req) ...@@ -357,7 +356,6 @@ cnt_transmit(struct worker *wrk, struct req *req)
/* RFC 7230, 3.3.3 */ /* RFC 7230, 3.3.3 */
status = http_GetStatus(req->resp); status = http_GetStatus(req->resp);
head = !strcmp(req->http0->hd[HTTP_HDR_METHOD].b, "HEAD"); head = !strcmp(req->http0->hd[HTTP_HDR_METHOD].b, "HEAD");
err = 0;
if (boc != NULL) if (boc != NULL)
req->resp_len = clval; req->resp_len = clval;
...@@ -371,27 +369,16 @@ cnt_transmit(struct worker *wrk, struct req *req) ...@@ -371,27 +369,16 @@ cnt_transmit(struct worker *wrk, struct req *req)
sendbody = 1; sendbody = 1;
} }
if (!req->disable_esi && req->resp_len != 0 && if (req->filter_list == NULL)
ObjHasAttr(wrk, req->objcore, OA_ESIDATA) && req->filter_list = resp_Get_Filter_List(req);
VDP_Push(req, &VDP_esi, NULL) < 0) if (req->filter_list == NULL ||
err++; VCL_StackVDP(req, req->vcl, req->filter_list)) {
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) {
VSLb(req->vsl, SLT_Error, "Failure to push processors"); VSLb(req->vsl, SLT_Error, "Failure to push processors");
req->doclose = SC_OVERLOAD; req->doclose = SC_OVERLOAD;
} else { } else {
if (cache_param->http_range_support && status == 200)
http_ForceHeader(req->resp, H_Accept_Ranges, "bytes");
if (status < 200 || status == 204) { if (status < 200 || status == 204) {
// rfc7230,l,1691,1695 // rfc7230,l,1691,1695
http_Unset(req->resp, H_Content_Length); http_Unset(req->resp, H_Content_Length);
...@@ -417,8 +404,8 @@ cnt_transmit(struct worker *wrk, struct req *req) ...@@ -417,8 +404,8 @@ cnt_transmit(struct worker *wrk, struct req *req)
} }
if (req->resp_len == 0) if (req->resp_len == 0)
sendbody = 0; sendbody = 0;
req->transport->deliver(req, boc, sendbody);
} }
req->transport->deliver(req, boc, sendbody);
VSLb_ts_req(req, "Resp", W_TIM_real(wrk)); VSLb_ts_req(req, "Resp", W_TIM_real(wrk));
...@@ -438,6 +425,7 @@ cnt_transmit(struct worker *wrk, struct req *req) ...@@ -438,6 +425,7 @@ cnt_transmit(struct worker *wrk, struct req *req)
(void)HSH_DerefObjCore(wrk, &req->objcore, HSH_RUSH_POLICY); (void)HSH_DerefObjCore(wrk, &req->objcore, HSH_RUSH_POLICY);
http_Teardown(req->resp); http_Teardown(req->resp);
req->filter_list = NULL;
req->res_mode = 0; req->res_mode = 0;
return (REQ_FSM_DONE); return (REQ_FSM_DONE);
} }
......
...@@ -188,6 +188,7 @@ int VDP_DeliverObj(struct req *req); ...@@ -188,6 +188,7 @@ int VDP_DeliverObj(struct req *req);
extern const struct vdp VDP_gunzip; extern const struct vdp VDP_gunzip;
extern const struct vdp VDP_esi; extern const struct vdp VDP_esi;
extern const struct vdp VDP_range;
/* cache_expire.c */ /* cache_expire.c */
void EXP_Init(void); void EXP_Init(void);
...@@ -290,8 +291,6 @@ typedef void obj_event_f(struct worker *, void *priv, struct objcore *, ...@@ -290,8 +291,6 @@ typedef void obj_event_f(struct worker *, void *priv, struct objcore *,
uintptr_t ObjSubscribeEvents(obj_event_f *, void *, unsigned mask); uintptr_t ObjSubscribeEvents(obj_event_f *, void *, unsigned mask);
void ObjUnsubscribeEvents(uintptr_t *); void ObjUnsubscribeEvents(uintptr_t *);
/* cache_panic.c */ /* cache_panic.c */
void PAN_Init(void); void PAN_Init(void);
int PAN_already(struct vsb *, const void *); int PAN_already(struct vsb *, const void *);
...@@ -308,9 +307,6 @@ int Pool_TrySumstat(const struct worker *wrk); ...@@ -308,9 +307,6 @@ int Pool_TrySumstat(const struct worker *wrk);
void Pool_PurgeStat(unsigned nobj); void Pool_PurgeStat(unsigned nobj);
int Pool_Task_Any(struct pool_task *task, enum task_prio prio); 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 */ /* cache_req.c */
struct req *Req_New(const struct worker *, struct sess *); struct req *Req_New(const struct worker *, struct sess *);
void Req_Release(struct req *); void Req_Release(struct req *);
...@@ -405,11 +401,15 @@ int VCL_IterDirector(struct cli *, const char *, vcl_be_func *, void *); ...@@ -405,11 +401,15 @@ int VCL_IterDirector(struct cli *, const char *, vcl_be_func *, void *);
/* cache_vcl_vrt.c */ /* cache_vcl_vrt.c */
void VCL_VRT_Init(void); void VCL_VRT_Init(void);
int VCL_StackVFP(struct vfp_ctx *, const struct vcl *, const char *);
/* cache_vrt.c */ /* cache_vrt.c */
void pan_privs(struct vsb *, const struct vrt_privs *); 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 */ /* cache_vrt_priv.c */
extern struct vrt_privs cli_task_privs[1]; extern struct vrt_privs cli_task_privs[1];
......
...@@ -190,6 +190,7 @@ VCL_StackVFP(struct vfp_ctx *vc, const struct vcl *vcl, const char *fl) ...@@ -190,6 +190,7 @@ VCL_StackVFP(struct vfp_ctx *vc, const struct vcl *vcl, const char *fl)
{ {
const struct vfilter *vp; const struct vfilter *vp;
AN(fl);
VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl); VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl);
while (1) { while (1) {
...@@ -203,6 +204,27 @@ VCL_StackVFP(struct vfp_ctx *vc, const struct vcl *vcl, const char *fl) ...@@ -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 void
VCL_VRT_Init(void) VCL_VRT_Init(void)
{ {
...@@ -213,15 +235,16 @@ VCL_VRT_Init(void) ...@@ -213,15 +235,16 @@ VCL_VRT_Init(void)
VRT_AddVFP(NULL, &VFP_esi_gzip); VRT_AddVFP(NULL, &VFP_esi_gzip);
VRT_AddVDP(NULL, &VDP_esi); VRT_AddVDP(NULL, &VDP_esi);
VRT_AddVDP(NULL, &VDP_gunzip); 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 * 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; unsigned u;
struct vsb vsb[1]; struct vsb vsb[1];
...@@ -253,7 +276,7 @@ filter_on_ws(struct ws *ws, filter_list_t *func, const void *arg) ...@@ -253,7 +276,7 @@ filter_on_ws(struct ws *ws, filter_list_t *func, const void *arg)
*/ */
static void v_matchproto_(filter_list_t) 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 struct busyobj *bo;
const char *p; const char *p;
...@@ -328,15 +351,29 @@ VBF_Get_Filter_List(struct busyobj *bo) ...@@ -328,15 +351,29 @@ VBF_Get_Filter_List(struct busyobj *bo)
*/ */
static void v_matchproto_(filter_list_t) 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); 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) resp_Get_Filter_List(struct req *req)
{ {
CHECK_OBJ_NOTNULL(req, REQ_MAGIC); CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
......
...@@ -39,6 +39,8 @@ client c1 { ...@@ -39,6 +39,8 @@ client c1 {
expect resp.http.x-of == <undef> expect resp.http.x-of == <undef>
} -run } -run
varnish v1 -vsl_catchup
client c2 { client c2 {
txreq -url /baz txreq -url /baz
rxresp rxresp
......
...@@ -48,7 +48,6 @@ varnish v1 -cliok "param.set http_gzip_support true" -vcl+backend { ...@@ -48,7 +48,6 @@ varnish v1 -cliok "param.set http_gzip_support true" -vcl+backend {
} }
sub vcl_deliver { sub vcl_deliver {
set resp.http.filters = resp.filters; set resp.http.filters = resp.filters;
set resp.filters = "";
} }
} -start } -start
...@@ -57,18 +56,30 @@ client c1 { ...@@ -57,18 +56,30 @@ client c1 {
rxresp rxresp
expect resp.http.content-encoding == <undef> expect resp.http.content-encoding == <undef>
expect resp.bodylen == 41 expect resp.bodylen == 41
} -run
varnish v1 -vsl_catchup
client c1 {
txreq -url /bar -hdr "Accept-Encoding: gzip" txreq -url /bar -hdr "Accept-Encoding: gzip"
rxresp rxresp
expect resp.http.content-encoding == <undef> expect resp.http.content-encoding == <undef>
expect resp.bodylen == 42 expect resp.bodylen == 42
} -run
varnish v1 -vsl_catchup
client c1 {
txreq -url /foobar -hdr "Accept-Encoding: gzip" txreq -url /foobar -hdr "Accept-Encoding: gzip"
rxresp rxresp
expect resp.http.content-encoding == "gzip" expect resp.http.content-encoding == "gzip"
gunzip gunzip
expect resp.bodylen == 43 expect resp.bodylen == 43
} -run
varnish v1 -vsl_catchup
client c1 {
txreq -url /foobar txreq -url /foobar
rxresp rxresp
expect resp.http.content-encoding == <undef> expect resp.http.content-encoding == <undef>
......
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