blob: 309c4ae6ad275a50f4a422dde766837bfc7ecd61 [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 {
Willy Tarreaue1465c12021-05-09 14:41:41 +020043 global
44 # WT: limit false-positives causing "HTTP header incomplete" due to
45 # idle server connections being randomly used and randomly expiring
46 # under us.
47 tune.idle-pool.shared off
48
Remi Tricot-Le Bretona6476112020-10-28 17:52:53 +010049 defaults
50 mode http
Remi Tricot-Le Bretona6476112020-10-28 17:52:53 +010051 timeout connect 1s
52 timeout client 1s
53 timeout server 1s
54
55 frontend fe
56 bind "fd@${fe}"
57 use_backend cache_control_be if { path_beg /cache_control }
58 use_backend future_expires_be if { path_beg /future }
59 default_backend past_expires_be
60
61 backend cache_control_be
62 # Expires header should be ignored since a Cache-Control one is present
63 http-request cache-use my_cache
64 server www ${s1_addr}:${s1_port}
65 http-response set-header X-Cache-Hit %[res.cache_hit]
66 http-response set-header Expires %[date(-1),http_date]
67 http-response cache-store my_cache
68
69 backend future_expires_be
70 # Expires value set in the future (current_time+5s)
71 http-request cache-use my_cache
72 server www ${s2_addr}:${s2_port}
73 http-response set-header X-Cache-Hit %[res.cache_hit]
74 http-response set-header Expires %[date(5),http_date]
75 http-response cache-store my_cache
76
77 backend past_expires_be
78 # Expires value set in the past
79 http-request cache-use my_cache
80 server www ${s3_addr}:${s3_port}
81 http-response set-header X-Cache-Hit %[res.cache_hit]
82 http-response set-header Expires %[date(-1),http_date]
83 http-response cache-store my_cache
84
85 cache my_cache
86 total-max-size 3
87 max-age 20
88 max-object-size 3072
89} -start
90
91
92client c1 -connect ${h1_fe_sock} {
93 txreq -url "/cache_control"
94 rxresp
95 expect resp.status == 200
96 expect resp.bodylen == 45
97
98 txreq -url "/cache_control"
99 rxresp
100 expect resp.status == 200
101 expect resp.bodylen == 45
102 expect resp.http.X-Cache-Hit == 1
103
104 txreq -url "/future"
105 rxresp
106 expect resp.status == 200
107 expect resp.bodylen == 48
108
109 txreq -url "/future"
110 rxresp
111 expect resp.status == 200
112 expect resp.bodylen == 48
113 expect resp.http.X-Cache-Hit == 1
114
115 txreq -url "/past"
116 rxresp
117 expect resp.status == 200
118 expect resp.bodylen == 48
119
120 txreq -url "/past"
121 rxresp
122 expect resp.status == 200
123 expect resp.bodylen == 51
124 expect resp.http.X-Cache-Hit == 0
125
126} -run
127