blob: 51c7487481de52a15312f14be8a5499a1a5b1213 [file] [log] [blame]
Remi Tricot-Le Bretona6476112020-10-28 17:52:53 +01001varnishtest "Expires support"
2
3#REQUIRE_VERSION=2.3
4
5feature ignore_unknown_macro
6
7server s1 {
8 rxreq
9 txresp -nolen -hdr "Transfer-Encoding: chunked" \
10 -hdr "Cache-Control: max-age=5"
11 chunkedlen 15
12 chunkedlen 15
13 chunkedlen 15
14 chunkedlen 0
15} -start
16
17server s2 {
18 rxreq
19 txresp -nolen -hdr "Transfer-Encoding: chunked"
20 chunkedlen 16
21 chunkedlen 16
22 chunkedlen 16
23 chunkedlen 0
24} -start
25
26server s3 {
27 rxreq
28 txresp -nolen -hdr "Transfer-Encoding: chunked"
29 chunkedlen 16
30 chunkedlen 16
31 chunkedlen 16
32 chunkedlen 0
33
34 rxreq
35 txresp -nolen -hdr "Transfer-Encoding: chunked"
36 chunkedlen 17
37 chunkedlen 17
38 chunkedlen 17
39 chunkedlen 0
40} -start
41
42haproxy h1 -conf {
43 defaults
44 mode http
45 ${no-htx} option http-use-htx
46 timeout connect 1s
47 timeout client 1s
48 timeout server 1s
49
50 frontend fe
51 bind "fd@${fe}"
52 use_backend cache_control_be if { path_beg /cache_control }
53 use_backend future_expires_be if { path_beg /future }
54 default_backend past_expires_be
55
56 backend cache_control_be
57 # Expires header should be ignored since a Cache-Control one is present
58 http-request cache-use my_cache
59 server www ${s1_addr}:${s1_port}
60 http-response set-header X-Cache-Hit %[res.cache_hit]
61 http-response set-header Expires %[date(-1),http_date]
62 http-response cache-store my_cache
63
64 backend future_expires_be
65 # Expires value set in the future (current_time+5s)
66 http-request cache-use my_cache
67 server www ${s2_addr}:${s2_port}
68 http-response set-header X-Cache-Hit %[res.cache_hit]
69 http-response set-header Expires %[date(5),http_date]
70 http-response cache-store my_cache
71
72 backend past_expires_be
73 # Expires value set in the past
74 http-request cache-use my_cache
75 server www ${s3_addr}:${s3_port}
76 http-response set-header X-Cache-Hit %[res.cache_hit]
77 http-response set-header Expires %[date(-1),http_date]
78 http-response cache-store my_cache
79
80 cache my_cache
81 total-max-size 3
82 max-age 20
83 max-object-size 3072
84} -start
85
86
87client c1 -connect ${h1_fe_sock} {
88 txreq -url "/cache_control"
89 rxresp
90 expect resp.status == 200
91 expect resp.bodylen == 45
92
93 txreq -url "/cache_control"
94 rxresp
95 expect resp.status == 200
96 expect resp.bodylen == 45
97 expect resp.http.X-Cache-Hit == 1
98
99 txreq -url "/future"
100 rxresp
101 expect resp.status == 200
102 expect resp.bodylen == 48
103
104 txreq -url "/future"
105 rxresp
106 expect resp.status == 200
107 expect resp.bodylen == 48
108 expect resp.http.X-Cache-Hit == 1
109
110 txreq -url "/past"
111 rxresp
112 expect resp.status == 200
113 expect resp.bodylen == 48
114
115 txreq -url "/past"
116 rxresp
117 expect resp.status == 200
118 expect resp.bodylen == 51
119 expect resp.http.X-Cache-Hit == 0
120
121} -run
122