Commit 64693455 authored by Federico G. Schwindt's avatar Federico G. Schwindt

Use a weak comparison function for If-None-Match

As per RFC 7232.

Fixes #1816.
parent e4637bb6
......@@ -232,6 +232,16 @@ RFC2616_Req_Gzip(const struct http *hp)
/*--------------------------------------------------------------------*/
static inline int
rfc2616_weak_compare(const char *p, const char *e)
{
if (p[0] == 'W' && p[1] == '/')
p += 2;
if (e[0] == 'W' && e[1] == '/')
e += 2;
return (strcmp(p, e) != 0);
}
int
RFC2616_Do_Cond(const struct req *req)
{
......@@ -239,12 +249,20 @@ RFC2616_Do_Cond(const struct req *req)
double ims, lm;
int do_cond = 0;
/* RFC 2616 13.3.4 states we need to match both ETag
and If-Modified-Since if present*/
/*
* RFC 2616 13.3.4 states we need to match both ETag and
* If-Modified-Since if present.
*/
if (http_GetHdr(req->http, H_If_None_Match, &p) &&
http_GetHdr(req->resp, H_ETag, &e)) {
if (rfc2616_weak_compare(p, e))
return (0);
do_cond = 1;
}
if (http_GetHdr(req->http, H_If_Modified_Since, &p) ) {
if (http_GetHdr(req->http, H_If_Modified_Since, &p)) {
ims = VTIM_parse(p);
if (ims > req->t_req) /* [RFC2616 14.25] */
if (!ims || ims > req->t_req) /* [RFC2616 14.25] */
return (0);
AZ(ObjGetDouble(req->wrk, req->objcore, OA_LASTMODIFIED, &lm));
if (lm > ims)
......@@ -252,13 +270,6 @@ RFC2616_Do_Cond(const struct req *req)
do_cond = 1;
}
if (http_GetHdr(req->http, H_If_None_Match, &p) &&
http_GetHdr(req->resp, H_ETag, &e)) {
if (strcmp(p,e) != 0)
return (0);
do_cond = 1;
}
return (do_cond);
}
......
......@@ -4,6 +4,10 @@ server s1 {
rxreq
expect req.url == /
txresp -hdr {ETag: "123456789"} -bodylen 10
rxreq
expect req.url == /other
txresp -hdr {ETag: W/"123456789"} -bodylen 10
} -start
varnish v1 -vcl+backend { } -start
......@@ -22,4 +26,36 @@ client c1 {
txreq -hdr {If-None-Match: "123456789"}
rxresp -no_obj
expect resp.status == 304
txreq -hdr {If-None-Match: W/"12345678"}
rxresp
expect resp.status == 200
txreq -hdr {If-None-Match: W/"123456789"}
rxresp -no_obj
expect resp.status == 304
} -run
client c2 {
txreq -url /other
rxresp
expect resp.status == 200
expect resp.bodylen == 10
expect resp.http.etag == {W/"123456789"}
txreq -url /other -hdr {If-None-Match: "12345678"}
rxresp
expect resp.status == 200
txreq -url /other -hdr {If-None-Match: "123456789"}
rxresp -no_obj
expect resp.status == 304
txreq -url /other -hdr {If-None-Match: W/"12345678"}
rxresp
expect resp.status == 200
txreq -url /other -hdr {If-None-Match: W/"123456789"}
rxresp -no_obj
expect resp.status == 304
} -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