Skip to content

Commit

Permalink
Proper handling of duplicate headers on IMS headers merge
Browse files Browse the repository at this point in the history
This fixes a problem when a backend replies with 304 Not Modified
(after a http conditional request from varnish) and does not supply a
header that was duplicate in the cached object.

Before this patch, varnish would only supply (by copying from the
expired object) the first instance of a duplicate header.
  • Loading branch information
hermunn authored and mbgrydeland committed Mar 29, 2016
1 parent a50c99f commit d6ed244
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bin/varnishd/cache/cache_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@ HTTP_Merge(struct worker *wrk, struct objcore *oc, struct http *to)
const char *ptr;
unsigned u;
const char *p;
unsigned nhd_before_merge;

CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
Expand All @@ -1009,10 +1010,12 @@ HTTP_Merge(struct worker *wrk, struct objcore *oc, struct http *to)
http_SetH(to, u, ptr);
ptr = strchr(ptr, '\0') + 1;
}
nhd_before_merge = to->nhd;
while (*ptr != '\0') {
p = strchr(ptr, ':');
AN(p);
if (!http_findhdr(to, p - ptr, ptr))
u = http_findhdr(to, p - ptr, ptr);
if (u == 0 || u >= nhd_before_merge)
http_SetHeader(to, ptr);
ptr = strchr(ptr, '\0') + 1;
}
Expand Down
48 changes: 48 additions & 0 deletions bin/varnishtest/tests/r01879.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
varnishtest "r01879: Check duplicate headers handling on IMS header merge"

server s1 {
rxreq
txresp -hdr {etag: "foo"} -hdr "foo: a" -hdr "foo: b" -body "bdy"
rxreq
expect req.http.if-none-match == {"foo"}
txresp -status 304 -hdr {etag: "foo"} -hdr "foo: c" -hdr "foo: d"
rxreq
txresp -hdr {etag: "bar"} -hdr "foo: a" -hdr "foo: b" -body "bdy"
rxreq
expect req.http.if-none-match == {"bar"}
txresp -status 304 -hdr {etag: "bar"}
} -start

varnish v1 -vcl+backend {
import std;

sub vcl_backend_response {
set beresp.ttl = 0.00001s;
set beresp.grace = 0.1s;
set beresp.keep = 9999s;
}
sub vcl_deliver {
std.collect(resp.http.foo);
}
} -start

client c1 {
txreq
rxresp
expect resp.http.foo == "a, b"
delay .5
txreq
rxresp
expect resp.http.foo == "c, d"
delay .5
} -run

client c2 {
txreq
rxresp
expect resp.http.foo == "a, b"
delay .5
txreq
rxresp
expect resp.http.foo == "a, b"
} -run

0 comments on commit d6ed244

Please sign in to comment.