From: phk Date: Thu, 5 Jul 2007 09:16:19 +0000 (+0000) Subject: Add support for removing HTTP header lines: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb6c70a60e6ee2727af28f60876eadf8439012a9;p=varnish Add support for removing HTTP header lines: sub vcl_deliver { remove resp.http.etag ; remove resp.http.server ; } git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1645 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 61dc85f7..9ba90593 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -427,6 +427,7 @@ int http_DissectRequest(struct worker *w, struct http *sp, int fd); int http_DissectResponse(struct worker *w, struct http *sp, int fd); void http_DoConnection(struct sess *sp); void http_CopyHome(struct worker *w, int fd, struct http *hp); +void http_Unset(struct http *hp, const char *hdr); #define HTTPH(a, b, c, d, e, f, g) extern char b[]; diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 24d02b11..65ddf873 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -176,7 +176,7 @@ http_Setup(struct http *hp, void *space, unsigned len) static int -http_IsHdr(struct http_hdr *hh, char *hdr) +http_IsHdr(struct http_hdr *hh, const char *hdr) { unsigned l; @@ -948,6 +948,22 @@ http_PrintfHeader(struct worker *w, int fd, struct http *to, const char *fmt, .. to->nhd++; } } +/*--------------------------------------------------------------------*/ + +void +http_Unset(struct http *hp, const char *hdr) +{ + unsigned u, v; + + for (v = u = HTTP_HDR_FIRST; u < hp->nhd; u++) { + if (http_IsHdr(&hp->hd[u], hdr)) + continue; + if (v != u) + memcpy(&hp->hd[v], &hp->hd[u], sizeof hp->hd[v]); + v++; + } + hp->nhd = v; +} /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 9ceecca9..7cdef770 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "shmlog.h" #include "heritage.h" @@ -70,10 +71,9 @@ VRT_count(struct sess *sp, unsigned u) /*--------------------------------------------------------------------*/ -char * -VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n) +static struct http * +vrt_selecthttp(struct sess *sp, enum gethdr_e where) { - char *p; struct http *hp; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -94,6 +94,17 @@ VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n) INCOMPL(); } CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); + return (hp); +} + +char * +VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n) +{ + char *p; + struct http *hp; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + hp = vrt_selecthttp(sp, where); if (!http_GetHdr(hp, n, &p)) return (NULL); return (p); @@ -101,6 +112,27 @@ VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n) /*--------------------------------------------------------------------*/ +void +VRT_SetHdr(struct sess *sp , enum gethdr_e where, const char *hdr, ...) +{ + struct http *hp; + va_list ap; + const char *p; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + hp = vrt_selecthttp(sp, where); + va_start(ap, hdr); + p = va_arg(ap, const char *); + if (p == NULL) { + http_Unset(hp, hdr); + } else { + INCOMPL(); + } + va_end(ap); +} + +/*--------------------------------------------------------------------*/ + void VRT_handling(struct sess *sp, unsigned hand) { diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index 150e5b57..7f284681 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -76,6 +76,7 @@ int VRT_switch_config(const char *); enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ }; char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *); +void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, ...); void VRT_handling(struct sess *sp, unsigned hand); /* Backend related */ diff --git a/varnish-cache/lib/libvcl/vcc_action.c b/varnish-cache/lib/libvcl/vcc_action.c index 7294ecba..32ad8f22 100644 --- a/varnish-cache/lib/libvcl/vcc_action.c +++ b/varnish-cache/lib/libvcl/vcc_action.c @@ -103,6 +103,16 @@ illegal_assignment(struct tokenlist *tl, const char *type) " only '=' is legal for %s\n", type); } +static void +check_writebit(struct tokenlist *tl, struct var *vp) +{ + + if (vp->access == V_RW || vp->access == V_WO) + return; + vsb_printf(tl->sb, "Variable %.*s cannot be modified.\n", PF(tl->t)); + vcc_ErrWhere(tl, tl->t); +} + static void parse_set(struct tokenlist *tl) { @@ -115,12 +125,8 @@ parse_set(struct tokenlist *tl) vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); assert(vp != NULL); - if (vp->access != V_RW && vp->access != V_WO) { - vsb_printf(tl->sb, "Variable %.*s cannot be written.\n", - PF(vt)); - vcc_ErrWhere(tl, vt); - return; - } + check_writebit(tl, vp); + ERRCHK(tl); Fb(tl, 1, "%s", vp->lname); vcc_NextToken(tl); switch (vp->fmt) { @@ -215,6 +221,31 @@ parse_set(struct tokenlist *tl) /*--------------------------------------------------------------------*/ +static void +parse_remove(struct tokenlist *tl) +{ + struct var *vp; + struct token *vt; + + vcc_NextToken(tl); + ExpectErr(tl, VAR); + vt = tl->t; + vp = vcc_FindVar(tl, tl->t, vcc_vars); + if (vp->fmt != STRING) { + vsb_printf(tl->sb, + "Only STRING variables can be removed.\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + check_writebit(tl, vp); + ERRCHK(tl); + Fb(tl, 1, "%s, 0);\n", vp->lname); + vcc_NextToken(tl); + ExpectErr(tl, ';'); +} + +/*--------------------------------------------------------------------*/ + typedef void action_f(struct tokenlist *tl); static struct action_table { @@ -228,6 +259,7 @@ static struct action_table { #undef VCL_RET_MAC_E { "call", parse_call }, { "set", parse_set }, + { "remove", parse_remove }, { NULL, NULL } }; diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 4d581cee..d6aed052 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -432,6 +432,7 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, "\n"); vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ };\n"); vsb_cat(sb, "char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);\n"); + vsb_cat(sb, "void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, ...);\n"); vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/* Backend related */\n"); diff --git a/varnish-cache/lib/libvcl/vcc_var.c b/varnish-cache/lib/libvcl/vcc_var.c index 12e5a0b0..15b062f5 100644 --- a/varnish-cache/lib/libvcl/vcc_var.c +++ b/varnish-cache/lib/libvcl/vcc_var.c @@ -108,7 +108,7 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh) (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); v->rname = p; - asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\")", wh, + asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\"", wh, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); v->lname = p;