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

Previously, we forced the request to "GET" on all fetches for cache

and this prevented users from implementing "purge on POST" semantics
by looking up the POST requests and ditching the object found.

Now we only overwrite the request with "GET" if it is a HEAD, (the
internal "wantbody" flag tells hos how the response should be composed.)

The testcase shold probably be elevated to VCL example, with suitable
footnotes about URL sanitizing etc.

Fixes #444



git-svn-id: http://www.varnish-cache.org/svn/trunk@4042 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 4f6d7e82
......@@ -979,7 +979,12 @@ cnt_recv(struct sess *sp)
return (0);
}
sp->wantbody = (strcmp(sp->http->hd[HTTP_HDR_REQ].b, "HEAD") != 0);
if (!strcmp(sp->http->hd[HTTP_HDR_REQ].b, "HEAD")) {
sp->wantbody = 0;
http_ForceGet(sp->http);
} else
sp->wantbody = 1;
sp->sendbody = 0;
switch(sp->handling) {
case VCL_RET_LOOKUP:
......
......@@ -555,23 +555,6 @@ http_copyh(struct http *to, const struct http *fm, unsigned n)
to->hdf[n] = fm->hdf[n];
}
static void
http_copyreq(struct http *to, const struct http *fm, int how)
{
CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
if ((how == HTTPH_R_PIPE) || (how == HTTPH_R_PASS)) {
http_copyh(to, fm, HTTP_HDR_REQ);
http_copyh(to, fm, HTTP_HDR_PROTO);
} else {
http_SetH(to, HTTP_HDR_REQ, "GET");
http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1");
}
http_copyh(to, fm, HTTP_HDR_URL);
}
void
http_ForceGet(struct http *to)
{
......@@ -660,7 +643,12 @@ http_FilterHeader(const struct sess *sp, unsigned how)
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
hp->logtag = HTTP_Tx;
http_copyreq(hp, sp->http, how);
http_copyh(hp, sp->http, HTTP_HDR_REQ);
http_copyh(hp, sp->http, HTTP_HDR_URL);
if (how == HTTPH_R_FETCH)
http_SetH(hp, HTTP_HDR_PROTO, "HTTP/1.1");
else
http_copyh(hp, sp->http, HTTP_HDR_PROTO);
http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how);
http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid);
http_PrintfHeader(sp->wrk, sp->fd, hp,
......
# $Id$
test "purging on POST"
server s1 {
rxreq
expect req.request == "GET"
txresp -body "1"
rxreq
expect req.request == "POST"
txresp -body "22"
rxreq
expect req.request == "POST"
txresp -body "333"
rxreq
expect req.request == "GET"
txresp -body "4444"
} -start
varnish v1 -vcl+backend {
sub vcl_recv {
if (req.request == "POST") {
/* Lookup so we find any cached object */
lookup;
}
}
sub vcl_hit {
if (req.request == "POST") {
/* Get rid of this object */
set obj.cacheable = false;
set obj.ttl = 0s;
pass;
}
}
sub vcl_miss {
if (req.request == "POST") {
/* Make sure we don't cache the POST result */
pass;
}
}
} -start
client c1 {
txreq
rxresp
expect resp.bodylen == 1
txreq -req POST
rxresp
expect resp.bodylen == 2
txreq -req POST
rxresp
expect resp.bodylen == 3
txreq
rxresp
expect resp.bodylen == 4
} -run
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