r1645 - in trunk/varnish-cache: bin/varnishd include lib/libvcl
phk at projects.linpro.no
phk at projects.linpro.no
Thu Jul 5 11:16:19 CEST 2007
Author: phk
Date: 2007-07-05 11:16:19 +0200 (Thu, 05 Jul 2007)
New Revision: 1645
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_http.c
trunk/varnish-cache/bin/varnishd/cache_vrt.c
trunk/varnish-cache/include/vrt.h
trunk/varnish-cache/lib/libvcl/vcc_action.c
trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
trunk/varnish-cache/lib/libvcl/vcc_var.c
Log:
Add support for removing HTTP header lines:
sub vcl_deliver {
remove resp.http.etag ;
remove resp.http.server ;
}
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-05 08:42:08 UTC (rev 1644)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-05 09:16:19 UTC (rev 1645)
@@ -427,6 +427,7 @@
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[];
Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-05 08:42:08 UTC (rev 1644)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-05 09:16:19 UTC (rev 1645)
@@ -176,7 +176,7 @@
static int
-http_IsHdr(struct http_hdr *hh, char *hdr)
+http_IsHdr(struct http_hdr *hh, const char *hdr)
{
unsigned l;
@@ -948,7 +948,23 @@
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;
+}
+
/*--------------------------------------------------------------------*/
unsigned
Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-05 08:42:08 UTC (rev 1644)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-05 09:16:19 UTC (rev 1645)
@@ -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 @@
/*--------------------------------------------------------------------*/
-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 @@
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);
@@ -102,6 +113,27 @@
/*--------------------------------------------------------------------*/
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)
{
Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h 2007-07-05 08:42:08 UTC (rev 1644)
+++ trunk/varnish-cache/include/vrt.h 2007-07-05 09:16:19 UTC (rev 1645)
@@ -76,6 +76,7 @@
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 */
Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-05 08:42:08 UTC (rev 1644)
+++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-05 09:16:19 UTC (rev 1645)
@@ -104,6 +104,16 @@
}
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)
{
struct var *vp;
@@ -115,12 +125,8 @@
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 @@
/*--------------------------------------------------------------------*/
+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 @@
#undef VCL_RET_MAC_E
{ "call", parse_call },
{ "set", parse_set },
+ { "remove", parse_remove },
{ NULL, NULL }
};
Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-05 08:42:08 UTC (rev 1644)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-05 09:16:19 UTC (rev 1645)
@@ -432,6 +432,7 @@
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");
Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-05 08:42:08 UTC (rev 1644)
+++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-05 09:16:19 UTC (rev 1645)
@@ -108,7 +108,7 @@
(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;
More information about the varnish-commit
mailing list