Commit e7cad46b authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add support for removing HTTP header lines:

	sub vcl_deliver {
		remove resp.http.etag ;
		remove resp.http.server ;
	}



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1645 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 0bc73fb0
......@@ -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[];
......
......@@ -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;
}
/*--------------------------------------------------------------------*/
......
......@@ -36,6 +36,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#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)
{
......
......@@ -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 */
......
......@@ -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 }
};
......
......@@ -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");
......
......@@ -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;
......
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