Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
bab12263
Commit
bab12263
authored
Oct 07, 2014
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use RFC5861::stale-while-revalidate to initialize beresp.grace
Submitted by: fgs
parent
54fe0853
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
0 deletions
+76
-0
cache.h
bin/varnishd/cache/cache.h
+1
-0
cache_fetch.c
bin/varnishd/cache/cache_fetch.c
+2
-0
cache_rfc2616.c
bin/varnishd/cache/cache_rfc2616.c
+32
-0
b00043.vtc
bin/varnishtest/tests/b00043.vtc
+41
-0
No files found.
bin/varnishd/cache/cache.h
View file @
bab12263
...
...
@@ -1158,6 +1158,7 @@ unsigned RFC2616_Req_Gzip(const struct http *);
int
RFC2616_Do_Cond
(
const
struct
req
*
sp
);
void
RFC2616_Weaken_Etag
(
struct
http
*
hp
);
void
RFC2616_Vary_AE
(
struct
http
*
hp
);
void
RFC5861_Stale
(
const
struct
busyobj
*
);
/* stevedore.c */
int
STV_NewObject
(
struct
objcore
*
,
struct
worker
*
,
...
...
bin/varnishd/cache/cache_fetch.c
View file @
bab12263
...
...
@@ -365,6 +365,8 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
EXP_Clr
(
&
bo
->
fetch_objcore
->
exp
);
RFC2616_Ttl
(
bo
,
now
);
RFC5861_Stale
(
bo
);
/* private objects have negative TTL */
if
(
bo
->
fetch_objcore
->
flags
&
OC_F_PRIVATE
)
bo
->
fetch_objcore
->
exp
.
ttl
=
-
1
.;
...
...
bin/varnishd/cache/cache_rfc2616.c
View file @
bab12263
...
...
@@ -275,3 +275,35 @@ RFC2616_Vary_AE(struct http *hp)
http_SetHeader
(
hp
,
"Vary: Accept-Encoding"
);
}
}
/*
* RFC5861 outlines a way to control the use of stale responses.
* We use this to initialize the grace period.
*/
void
RFC5861_Stale
(
const
struct
busyobj
*
bo
)
{
const
char
*
p
;
const
struct
http
*
hp
;
struct
exp
*
expp
;
expp
=
&
bo
->
fetch_objcore
->
exp
;
/*
* If we are not meant to cache this ignore any potential
* stale-while-revalidate values.
*/
if
(
expp
->
ttl
<
0
.)
return
;
hp
=
bo
->
beresp
;
if
(
http_GetHdrField
(
hp
,
H_Cache_Control
,
"stale-while-revalidate"
,
&
p
)
&&
p
!=
NULL
)
{
if
(
*
p
==
'-'
)
expp
->
grace
=
0
;
else
expp
->
grace
=
strtoul
(
p
,
NULL
,
0
);
}
}
bin/varnishtest/tests/b00043.vtc
0 → 100644
View file @
bab12263
varnishtest "Test stale-while-revalidate"
server s1 {
rxreq
txresp -hdr "Cache-Control: max-age=30, stale-while-revalidate=30"
rxreq
txresp -hdr "Cache-Control: max-age=0, stale-while-revalidate=30"
rxreq
txresp -hdr "Cache-Control: max-age=30, stale-while-revalidate=30" -hdr "Age: 40"
rxreq
txresp -status 500 -hdr "Cache-Control: max-age=30, stale-while-revalidate=30"
} -start
varnish v1 -vcl+backend {
sub vcl_backend_response {
set beresp.http.grace = beresp.grace;
set beresp.http.ttl = beresp.ttl;
}
} -start
client c1 {
txreq -url /1
rxresp
expect resp.http.grace == 30.000
expect resp.http.ttl == 30.000
txreq -url /2
rxresp
expect resp.http.grace == 30.000
expect resp.http.ttl == 0.000
txreq -url /3
rxresp
expect resp.http.grace == 30.000
expect resp.http.ttl == -10.000
txreq -url /4
rxresp
expect resp.http.grace == 10.000
expect resp.http.ttl == 0.000
} -run
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment