Commit 06e68d89 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move the Vary specification into the object worksspace instead of

using malloc space.

Otherwise -spersistent would resurrect objects without their Vary
specifications.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4277 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 3eb07d87
......@@ -652,7 +652,7 @@ void RES_BuildHttp(struct sess *sp);
void RES_WriteObj(struct sess *sp);
/* cache_vary.c */
void VRY_Create(const struct sess *sp);
struct vsb *VRY_Create(const struct sess *sp, struct http *hp);
int VRY_Match(const struct sess *sp, const unsigned char *vary);
/* cache_vcl.c */
......
......@@ -420,6 +420,7 @@ cnt_fetch(struct sess *sp)
struct http *hp, *hp2;
char *b;
unsigned handling, l;
struct vsb *vary;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
......@@ -515,13 +516,18 @@ cnt_fetch(struct sess *sp)
if (sp->wrk->cacheable) {
CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
vary = VRY_Create(sp, sp->wrk->beresp);
} else {
AZ(sp->objhead);
AZ(sp->objcore);
vary = NULL;
}
l = http_EstimateWS(sp->wrk->beresp, HTTPH_A_INS);
if (vary != NULL)
l += vsb_len(vary);
/* Space for producing a Content-Length: header */
l += 30;
......@@ -543,6 +549,15 @@ cnt_fetch(struct sess *sp)
BAN_NewObj(sp->obj);
}
if (vary != NULL) {
sp->obj->vary =
(void *)WS_Alloc(sp->obj->http->ws, vsb_len(vary));
AN(sp->obj->vary);
memcpy(sp->obj->vary, vsb_data(vary), vsb_len(vary));
vsb_delete(vary);
vary = NULL;
}
sp->obj->xid = sp->xid;
sp->obj->response = sp->err_code;
sp->obj->cacheable = sp->wrk->cacheable;
......@@ -619,7 +634,6 @@ cnt_fetch(struct sess *sp)
sp->obj->cacheable = 1;
if (sp->wrk->cacheable) {
VRY_Create(sp);
EXP_Insert(sp->obj);
AN(sp->obj->ban);
HSH_Unbusy(sp);
......
......@@ -701,9 +701,6 @@ HSH_Deref(struct worker *w, struct object **oo)
DSL(0x40, SLT_Debug, 0, "Object %u workspace min free %u",
o->xid, WS_Free(o->ws_o));
if (o->vary != NULL)
free(o->vary);
ESI_Destroy(o);
if (o->objcore != NULL && o->objcore->smp_seg != NULL) {
SMP_FreeObj(o);
......
......@@ -63,16 +63,16 @@ SVNID("$Id$")
#include "cache.h"
void
VRY_Create(const struct sess *sp)
struct vsb *
VRY_Create(const struct sess *sp, struct http *hp)
{
char *v, *p, *q, *h, *e;
struct vsb *sb, *sbh;
int l;
/* No Vary: header, no worries */
if (!http_GetHdr(sp->obj->http, H_Vary, &v))
return;
if (!http_GetHdr(hp, H_Vary, &v))
return (NULL);
/* For vary matching string */
sb = vsb_newauto();
......@@ -126,16 +126,10 @@ VRY_Create(const struct sess *sp)
/* Terminate vary matching string */
vsb_printf(sb, "%c", 0);
vsb_delete(sbh);
vsb_finish(sb);
AZ(vsb_overflowed(sb));
l = vsb_len(sb);
assert(l >= 0);
sp->obj->vary = malloc(l);
AN(sp->obj->vary);
memcpy(sp->obj->vary, vsb_data(sb), l);
vsb_delete(sb);
vsb_delete(sbh);
return(sb);
}
int
......
# $Id$
test "Check that Vary headers are stored"
shell "rm -f /tmp/__v1/_.per"
server s1 {
rxreq
txresp -hdr "Foo: foo1" -hdr "Vary: foo, bar"
rxreq
txresp -hdr "Foo: foo2" -hdr "Vary: foo, bar"
} -start
varnish v1 \
-arg "-spersistent,/tmp/__v1/_.per,10m" \
-vcl+backend { } -start
client c1 {
txreq -url "/foo" -hdr "foo: 1" -hdr "bar: 2"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1001"
expect resp.http.foo == "foo1"
txreq -url "/foo" -hdr "foo: 2" -hdr "bar: 1"
rxresp
expect resp.status == 200
expect resp.http.X-Varnish == "1002"
expect resp.http.foo == "foo2"
} -run
varnish v1 -expect n_object == 2
server s1 -wait
varnish v1 -stop
varnish v1 -start
varnish v1 -expect n_vampireobject == 2
client c1 {
txreq -url "/foo" -hdr "foo: 1" -hdr "bar: 2"
rxresp
expect resp.status == 200
#expect resp.http.X-Varnish == "1001"
expect resp.http.foo == "foo1"
txreq -url "/foo" -hdr "foo: 2" -hdr "bar: 1"
rxresp
expect resp.status == 200
#expect resp.http.X-Varnish == "1002"
expect resp.http.foo == "foo2"
} -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