blob: af8cbf0b8e4c08361a009c9f0b17904400d38234 [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" \
22 -hdr "Date: Thu, 22 Oct 2020 16:51:12 GMT"
23 chunkedlen 16
24 chunkedlen 16
25 chunkedlen 16
26 chunkedlen 0
27
28 # Response containing both a "Last-Modified" and a "Date" fields
29 # Should behave the same way as if the "Date" field was not here.
30 rxreq
31 expect req.url == "/last_modified_and_date"
32 txresp -nolen -hdr "Transfer-Encoding: chunked" \
33 -hdr "Last-Modified: Thu, 15 Oct 2020 14:24:38 GMT" \
34 -hdr "Date: Thu, 22 Oct 2020 16:51:12 GMT"
35 chunkedlen 17
36 chunkedlen 17
37 chunkedlen 17
38 chunkedlen 0
39} -start
40
41haproxy h1 -conf {
42 defaults
43 mode http
44 ${no-htx} option http-use-htx
45 timeout connect 1s
46 timeout client 1s
47 timeout server 1s
48
49 frontend fe
50 bind "fd@${fe}"
51 default_backend test
52
53 backend test
54 http-request cache-use my_cache
55 server www ${s1_addr}:${s1_port}
56 http-response cache-store my_cache
57
58 cache my_cache
59 total-max-size 3
60 max-age 20
61 max-object-size 3072
62} -start
63
64
65client c1 -connect ${h1_fe_sock} {
66 txreq -url "/last_modified"
67 rxresp
68 expect resp.status == 200
69 expect resp.bodylen == 45
70
71 txreq -url "/date"
72 rxresp
73 expect resp.status == 200
74 expect resp.bodylen == 48
75
76 txreq -url "/last_modified_and_date"
77 rxresp
78 expect resp.status == 200
79 expect resp.bodylen == 51
80
81
82 # Earlier date
83 # "Last-Modified" version
84 txreq -url "/last_modified" \
85 -hdr "If-Modified-Since: Thu, 15 Oct 2020 00:00:01 GMT"
86 rxresp
87 expect resp.status == 200
88 expect resp.bodylen == 45
89 # "Date" version
90 txreq -url "/date" \
91 -hdr "If-Modified-Since: Thu, 01 Oct 2020 00:00:01 GMT"
92 rxresp
93 expect resp.status == 200
94 expect resp.bodylen == 48
95 # "Last-Modified" and "Date" version
96 txreq -url "/last_modified_and_date" \
97 -hdr "If-Modified-Since: Thu, 15 Oct 2020 00:00:01 GMT"
98 rxresp
99 expect resp.status == 200
100 expect resp.bodylen == 51
101
102
103 # Same date
104 # "Last-Modified" version
105 txreq -url "/last_modified" \
106 -hdr "If-Modified-Since: Thu, 15 Oct 2020 22:23:24 GMT"
107 rxresp
108 expect resp.status == 304
109 expect resp.bodylen == 0
110 # "Date" version
111 txreq -url "/date" \
112 -hdr "If-Modified-Since: Thu, 22 Oct 2020 16:51:12 GMT"
113 rxresp
114 expect resp.status == 304
115 expect resp.bodylen == 0
116 # "Last-Modified" and "Date" version
117 txreq -url "/last_modified_and_date" \
118 -hdr "If-Modified-Since: Thu, 15 Oct 2020 16:51:12 GMT"
119 rxresp
120 expect resp.status == 304
121 expect resp.bodylen == 0
122
123
124 # Later date
125 # "Last-Modified" version
126 txreq -url "/last_modified" \
127 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
128 rxresp
129 expect resp.status == 304
130 expect resp.bodylen == 0
131 # "Date" version
132 txreq -url "/date" \
133 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
134 rxresp
135 expect resp.status == 304
136 expect resp.bodylen == 0
137 # "Last-Modified" and "Date" version
138 txreq -url "/last_modified_and_date" \
139 -hdr "If-Modified-Since: Thu, 22 Oct 2020 23:00:00 GMT"
140 rxresp
141 expect resp.status == 304
142 expect resp.bodylen == 0
143
144} -run
145