blob: a49e4732a4a51aef73c878a3743015dfd3aa636c [file] [log] [blame]
Remi Tricot-Le Breton53161d82020-10-23 10:51:28 +02001varnishtest "If-Modified-Since support"
2
3#REQUIRE_VERSION=2.3
4
5feature ignore_unknown_macro
6
7server s1 {
8 # Response containing a "Last-Modified" field
9 rxreq
10 expect req.url == "/last_modified"
11 txresp -nolen -hdr "Transfer-Encoding: chunked" \
12 -hdr "Last-Modified: Thu, 15 Oct 2020 22:23:24 GMT"
13 chunkedlen 15
14 chunkedlen 15
15 chunkedlen 15
16 chunkedlen 0
17
18 # Response containing a "Date" field
19 rxreq
20 expect req.url == "/date"
21 txresp -nolen -hdr "Transfer-Encoding: chunked" \
Remi Tricot-Le Bretoncc9bf2e2020-11-12 11:14:41 +010022 -hdr "Date: Thu, 22 Oct 2020 16:51:12 GMT" \
23 -hdr "Cache-Control: max-age=5"
Remi Tricot-Le Breton53161d82020-10-23 10:51:28 +020024 chunkedlen 16
25 chunkedlen 16
26 chunkedlen 16
27 chunkedlen 0
28
29 # Response containing both a "Last-Modified" and a "Date" fields
30 # Should behave the same way as if the "Date" field was not here.
31 rxreq
32 expect req.url == "/last_modified_and_date"
33 txresp -nolen -hdr "Transfer-Encoding: chunked" \
34 -hdr "Last-Modified: Thu, 15 Oct 2020 14:24:38 GMT" \
35 -hdr "Date: Thu, 22 Oct 2020 16:51:12 GMT"
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 Breton53161d82020-10-23 10:51:28 +020049 defaults
50 mode http
Willy Tarreauf6739232021-11-18 17:46:22 +010051 timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
52 timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
53 timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
Remi Tricot-Le Breton53161d82020-10-23 10:51:28 +020054
55 frontend fe
56 bind "fd@${fe}"
57 default_backend test
58
59 backend test
60 http-request cache-use my_cache
61 server www ${s1_addr}:${s1_port}
62 http-response cache-store my_cache
63
Christopher Fauleta0e1a872022-11-16 17:19:42 +010064 # Remove Transfer-Encoding header because of a vtest issue with
65 # 304-Not-Modified responses
66 http-after-response del-header transfer-encoding if { status eq 304 }
67
Remi Tricot-Le Breton53161d82020-10-23 10:51:28 +020068 cache my_cache
69 total-max-size 3
70 max-age 20
71 max-object-size 3072
72} -start
73
74
75client c1 -connect ${h1_fe_sock} {
76 txreq -url "/last_modified"
77 rxresp
78 expect resp.status == 200
79 expect resp.bodylen == 45
80
81 txreq -url "/date"
82 rxresp
83 expect resp.status == 200
84 expect resp.bodylen == 48
85
86 txreq -url "/last_modified_and_date"
87 rxresp
88 expect resp.status == 200
89 expect resp.bodylen == 51
90
91
92 # Earlier date
93 # "Last-Modified" version
94 txreq -url "/last_modified" \
95 -hdr "If-Modified-Since: Thu, 15 Oct 2020 00:00:01 GMT"
96 rxresp
97 expect resp.status == 200
98 expect resp.bodylen == 45
99 # "Date" version
100 txreq -url "/date" \
101 -hdr "If-Modified-Since: Thu, 01 Oct 2020 00:00:01 GMT"
102 rxresp
103 expect resp.status == 200
104 expect resp.bodylen == 48
105 # "Last-Modified" and "Date" version
106 txreq -url "/last_modified_and_date" \
107 -hdr "If-Modified-Since: Thu, 15 Oct 2020 00:00:01 GMT"
108 rxresp
109 expect resp.status == 200
110 expect resp.bodylen == 51
111
112
113 # Same date
114 # "Last-Modified" version
115 txreq -url "/last_modified" \
116 -hdr "If-Modified-Since: Thu, 15 Oct 2020 22:23:24 GMT"
117 rxresp
118 expect resp.status == 304
119 expect resp.bodylen == 0
120 # "Date" version
121 txreq -url "/date" \
122 -hdr "If-Modified-Since: Thu, 22 Oct 2020 16:51:12 GMT"
123 rxresp
124 expect resp.status == 304
125 expect resp.bodylen == 0
126 # "Last-Modified" and "Date" version
127 txreq -url "/last_modified_and_date" \
128 -hdr "If-Modified-Since: Thu, 15 Oct 2020 16:51:12 GMT"
129 rxresp
130 expect resp.status == 304
131 expect resp.bodylen == 0
132
133
134 # Later date
135 # "Last-Modified" version
136 txreq -url "/last_modified" \
137 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
138 rxresp
139 expect resp.status == 304
140 expect resp.bodylen == 0
141 # "Date" version
142 txreq -url "/date" \
143 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
144 rxresp
145 expect resp.status == 304
146 expect resp.bodylen == 0
147 # "Last-Modified" and "Date" version
148 txreq -url "/last_modified_and_date" \
149 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
150 rxresp
151 expect resp.status == 304
152 expect resp.bodylen == 0
153
154} -run