From 9441eb37c7c87832771cb7357b0b3e1afd892e95 Mon Sep 17 00:00:00 2001 From: phk Date: Wed, 6 Sep 2006 09:54:49 +0000 Subject: [PATCH] Add support for inspecting response headers. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@919 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_vrt.c | 17 ++++++++++++++--- varnish-cache/include/vrt.h | 2 +- varnish-cache/include/vrt_obj.h | 2 ++ varnish-cache/lib/libvcl/vcc_compile.c | 8 ++++++-- varnish-cache/lib/libvcl/vcc_fixed_token.c | 2 +- varnish-cache/lib/libvcl/vcc_gen_obj.tcl | 1 + varnish-cache/lib/libvcl/vcc_obj.c | 6 ++++++ 7 files changed, 31 insertions(+), 7 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 6933e752..e969a736 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -42,13 +42,24 @@ VRT_count(struct sess *sp, unsigned u) /*--------------------------------------------------------------------*/ char * -VRT_GetHdr(struct sess *sp, const char *n) +VRT_GetHdr(struct sess *sp, int where, const char *n) { char *p; + struct http *hp; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - AN(sp->http); - if (!http_GetHdr(sp->http, n, &p)) + switch (where) { + case 1: + hp = sp->http; + break; + case 2: + hp = sp->vbc->http; + break; + default: + INCOMPL(); + } + CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); + if (!http_GetHdr(hp, n, &p)) return (NULL); return (p); } diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index 1915a0df..509a0578 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -45,7 +45,7 @@ int VRT_rewrite(const char *, const char *); void VRT_error(struct sess *, unsigned, const char *); int VRT_switch_config(const char *); -char *VRT_GetHdr(struct sess *, const char *); +char *VRT_GetHdr(struct sess *, int where, const char *); void VRT_handling(struct sess *sp, unsigned hand); /* Backend related */ diff --git a/varnish-cache/include/vrt_obj.h b/varnish-cache/include/vrt_obj.h index 1d06da02..a82aed93 100644 --- a/varnish-cache/include/vrt_obj.h +++ b/varnish-cache/include/vrt_obj.h @@ -30,3 +30,5 @@ double VRT_r_obj_ttl(struct sess *); void VRT_l_obj_ttl(struct sess *, double); const char * VRT_r_req_http_(struct sess *); void VRT_l_req_http_(struct sess *, const char *); +const char * VRT_r_resp_http_(struct sess *); +void VRT_l_resp_http_(struct sess *, const char *); diff --git a/varnish-cache/lib/libvcl/vcc_compile.c b/varnish-cache/lib/libvcl/vcc_compile.c index 73734bd5..cf33f610 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.c +++ b/varnish-cache/lib/libvcl/vcc_compile.c @@ -375,7 +375,7 @@ HeaderVar(struct tokenlist *tl, struct token *t, struct var *vh) { char *p; struct var *v; - int i; + int i, w; (void)tl; @@ -388,7 +388,11 @@ HeaderVar(struct tokenlist *tl, struct token *t, struct var *vh) p[i] = '\0'; v->name = p; v->fmt = STRING; - asprintf(&p, "VRT_GetHdr(sp, \"\\%03o%s:\")", + if (!memcmp(vh->name, "req.", 4)) + w = 1; + else + w = 2; + asprintf(&p, "VRT_GetHdr(sp, %d, \"\\%03o%s:\")", w, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); assert(p != NULL); v->rname = p; diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 721dad35..d716214a 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -513,7 +513,7 @@ vcl_output_lang_h(FILE *f) fputs("void VRT_error(struct sess *, unsigned, const char *);\n", f); fputs("int VRT_switch_config(const char *);\n", f); fputs("\n", f); - fputs("char *VRT_GetHdr(struct sess *, const char *);\n", f); + fputs("char *VRT_GetHdr(struct sess *, int where, const char *);\n", f); fputs("void VRT_handling(struct sess *sp, unsigned hand);\n", f); fputs("\n", f); fputs("/* Backend related */\n", f); diff --git a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl index 3f4d54d2..ee9317a6 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl @@ -22,6 +22,7 @@ set spobj { { obj.cacheable BOOL } { obj.ttl TIME } { req.http. HEADER } + { resp.http. HEADER } } set tt(IP) "const unsigned char *" diff --git a/varnish-cache/lib/libvcl/vcc_obj.c b/varnish-cache/lib/libvcl/vcc_obj.c index eff49746..6b12473d 100644 --- a/varnish-cache/lib/libvcl/vcc_obj.c +++ b/varnish-cache/lib/libvcl/vcc_obj.c @@ -62,6 +62,10 @@ struct var vcc_vars[] = { "VRT_r_req_http_(sp)", "VRT_l_req_http_(sp, ", }, + { "resp.http.", HEADER, 10, + "VRT_r_resp_http_(sp)", + "VRT_l_resp_http_(sp, ", + }, { NULL } }; @@ -98,4 +102,6 @@ const char *vrt_obj_h = "void VRT_l_obj_ttl(struct sess *, double);\n" "const char * VRT_r_req_http_(struct sess *);\n" "void VRT_l_req_http_(struct sess *, const char *);\n" + "const char * VRT_r_resp_http_(struct sess *);\n" + "void VRT_l_resp_http_(struct sess *, const char *);\n" ; -- 2.39.5