blob: 387fc7ec877e133ce57ec651119e5ceae838d177 [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
Christopher Faulet7c647672022-11-16 17:19:42 +010065 # Remove Transfer-Encoding header because of a vtest issue with
66 # 304-Not-Modified responses
67 http-after-response del-header transfer-encoding if { status eq 304 }
68
Remi Tricot-Le Breton53161d82020-10-23 10:51:28 +020069 cache my_cache
70 total-max-size 3
71 max-age 20
72 max-object-size 3072
73} -start
74
75
76client c1 -connect ${h1_fe_sock} {
77 txreq -url "/last_modified"
78 rxresp
79 expect resp.status == 200
80 expect resp.bodylen == 45
81
82 txreq -url "/date"
83 rxresp
84 expect resp.status == 200
85 expect resp.bodylen == 48
86
87 txreq -url "/last_modified_and_date"
88 rxresp
89 expect resp.status == 200
90 expect resp.bodylen == 51
91
92
93 # Earlier date
94 # "Last-Modified" version
95 txreq -url "/last_modified" \
96 -hdr "If-Modified-Since: Thu, 15 Oct 2020 00:00:01 GMT"
97 rxresp
98 expect resp.status == 200
99 expect resp.bodylen == 45
100 # "Date" version
101 txreq -url "/date" \
102 -hdr "If-Modified-Since: Thu, 01 Oct 2020 00:00:01 GMT"
103 rxresp
104 expect resp.status == 200
105 expect resp.bodylen == 48
106 # "Last-Modified" and "Date" version
107 txreq -url "/last_modified_and_date" \
108 -hdr "If-Modified-Since: Thu, 15 Oct 2020 00:00:01 GMT"
109 rxresp
110 expect resp.status == 200
111 expect resp.bodylen == 51
112
113
114 # Same date
115 # "Last-Modified" version
116 txreq -url "/last_modified" \
117 -hdr "If-Modified-Since: Thu, 15 Oct 2020 22:23:24 GMT"
118 rxresp
119 expect resp.status == 304
120 expect resp.bodylen == 0
121 # "Date" version
122 txreq -url "/date" \
123 -hdr "If-Modified-Since: Thu, 22 Oct 2020 16:51:12 GMT"
124 rxresp
125 expect resp.status == 304
126 expect resp.bodylen == 0
127 # "Last-Modified" and "Date" version
128 txreq -url "/last_modified_and_date" \
129 -hdr "If-Modified-Since: Thu, 15 Oct 2020 16:51:12 GMT"
130 rxresp
131 expect resp.status == 304
132 expect resp.bodylen == 0
133
134
135 # Later date
136 # "Last-Modified" version
137 txreq -url "/last_modified" \
138 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
139 rxresp
140 expect resp.status == 304
141 expect resp.bodylen == 0
142 # "Date" version
143 txreq -url "/date" \
144 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
145 rxresp
146 expect resp.status == 304
147 expect resp.bodylen == 0
148 # "Last-Modified" and "Date" version
149 txreq -url "/last_modified_and_date" \
150 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
151 rxresp
152 expect resp.status == 304
153 expect resp.bodylen == 0
154
155} -run