blob: 8ae1cce5d1d8b31389217b00cc74685a5d9f21f0 [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
51 ${no-htx} option http-use-htx
52 timeout connect 1s
53 timeout client 1s
54 timeout server 1s
55
56 frontend fe
57 bind "fd@${fe}"
58 default_backend test
59
60 backend test
61 http-request cache-use my_cache
62 server www ${s1_addr}:${s1_port}
63 http-response cache-store my_cache
64
65 cache my_cache
66 total-max-size 3
67 max-age 20
68 max-object-size 3072
69} -start
70
71
72client c1 -connect ${h1_fe_sock} {
73 txreq -url "/last_modified"
74 rxresp
75 expect resp.status == 200
76 expect resp.bodylen == 45
77
78 txreq -url "/date"
79 rxresp
80 expect resp.status == 200
81 expect resp.bodylen == 48
82
83 txreq -url "/last_modified_and_date"
84 rxresp
85 expect resp.status == 200
86 expect resp.bodylen == 51
87
88
89 # Earlier date
90 # "Last-Modified" version
91 txreq -url "/last_modified" \
92 -hdr "If-Modified-Since: Thu, 15 Oct 2020 00:00:01 GMT"
93 rxresp
94 expect resp.status == 200
95 expect resp.bodylen == 45
96 # "Date" version
97 txreq -url "/date" \
98 -hdr "If-Modified-Since: Thu, 01 Oct 2020 00:00:01 GMT"
99 rxresp
100 expect resp.status == 200
101 expect resp.bodylen == 48
102 # "Last-Modified" and "Date" version
103 txreq -url "/last_modified_and_date" \
104 -hdr "If-Modified-Since: Thu, 15 Oct 2020 00:00:01 GMT"
105 rxresp
106 expect resp.status == 200
107 expect resp.bodylen == 51
108
109
110 # Same date
111 # "Last-Modified" version
112 txreq -url "/last_modified" \
113 -hdr "If-Modified-Since: Thu, 15 Oct 2020 22:23:24 GMT"
114 rxresp
115 expect resp.status == 304
116 expect resp.bodylen == 0
117 # "Date" version
118 txreq -url "/date" \
119 -hdr "If-Modified-Since: Thu, 22 Oct 2020 16:51:12 GMT"
120 rxresp
121 expect resp.status == 304
122 expect resp.bodylen == 0
123 # "Last-Modified" and "Date" version
124 txreq -url "/last_modified_and_date" \
125 -hdr "If-Modified-Since: Thu, 15 Oct 2020 16:51:12 GMT"
126 rxresp
127 expect resp.status == 304
128 expect resp.bodylen == 0
129
130
131 # Later date
132 # "Last-Modified" version
133 txreq -url "/last_modified" \
134 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
135 rxresp
136 expect resp.status == 304
137 expect resp.bodylen == 0
138 # "Date" version
139 txreq -url "/date" \
140 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
141 rxresp
142 expect resp.status == 304
143 expect resp.bodylen == 0
144 # "Last-Modified" and "Date" version
145 txreq -url "/last_modified_and_date" \
146 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
147 rxresp
148 expect resp.status == 304
149 expect resp.bodylen == 0
150
151} -run
152