blob: 73e6e1bf687d2e4da98aa68c432a78f6e166b858 [file] [log] [blame]
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +01001
2varnishtest "Basic cache test"
3
4#REQUIRE_VERSION=1.9
5
6feature ignore_unknown_macro
7
8server s1 {
9 rxreq
Remi Tricot-Le Breton87c2f252020-11-12 11:14:41 +010010 txresp -nolen -hdr "Transfer-Encoding: chunked" \
11 -hdr "Cache-Control: max-age=5"
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +010012 chunkedlen 15
13 chunkedlen 15
14 chunkedlen 15
15 chunkedlen 0
16} -start
17
18server s2 {
19 rxreq
Remi Tricot-Le Breton87c2f252020-11-12 11:14:41 +010020 txresp -nolen -hdr "Transfer-Encoding: chunked" \
21 -hdr "Cache-Control: max-age=5"
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +010022 chunkedlen 16
23 chunkedlen 16
24 chunkedlen 16
25 chunkedlen 0
26} -start
27
28server s3 {
29 rxreq
Remi Tricot-Le Breton87c2f252020-11-12 11:14:41 +010030 txresp -nolen -hdr "Transfer-Encoding: chunked" \
31 -hdr "Cache-Control: max-age=5"
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +010032 chunkedlen 17
33 chunkedlen 17
34 chunkedlen 17
35 chunkedlen 0
36
37 rxreq
Remi Tricot-Le Breton87c2f252020-11-12 11:14:41 +010038 txresp -nolen -hdr "Transfer-Encoding: chunked" \
39 -hdr "Cache-Control: max-age=5"
Remi Tricot-Le Bretonbf971212020-10-27 11:55:57 +010040 chunkedlen 17
41 chunkedlen 17
42 chunkedlen 17
43 chunkedlen 0
44} -start
45
46haproxy h1 -conf {
47 defaults
48 mode http
49 ${no-htx} option http-use-htx
50 timeout connect 1s
51 timeout client 1s
52 timeout server 1s
53
54 frontend fe
55 bind "fd@${fe}"
56 use_backend first_be if { path_beg /first }
57 use_backend nocache_be if { path_beg /nocache }
58 default_backend second_be
59
60 backend first_be
61 http-request cache-use first_cache
62 server www ${s1_addr}:${s1_port}
63 http-response cache-store first_cache
64 http-response set-header X-Cache-Hit %[res.cache_hit]
65 http-response set-header X-Cache-Name %[res.cache_name]
66
67 backend second_be
68 http-request cache-use second_cache
69 server www ${s2_addr}:${s2_port}
70 http-response cache-store second_cache
71 http-response set-header X-Cache-Hit %[res.cache_hit]
72 http-response set-header X-Cache-Name %[res.cache_name]
73
74 backend nocache_be
75 server www ${s3_addr}:${s3_port}
76 http-response set-header X-Cache-Hit %[res.cache_hit]
77 http-response set-header X-Cache-Name %[res.cache_name]
78
79 cache first_cache
80 total-max-size 3
81 max-age 40
82 max-object-size 3000
83
84 cache second_cache
85 total-max-size 3
86 max-age 20
87 max-object-size 3072
88} -start
89
90
91client c1 -connect ${h1_fe_sock} {
92 txreq -url "/first"
93 rxresp
94 expect resp.status == 200
95 expect resp.bodylen == 45
96 expect resp.http.X-Cache-Hit == 0
97 expect resp.http.X-Cache-Name == ""
98
99 txreq -url "/second"
100 rxresp
101 expect resp.status == 200
102 expect resp.bodylen == 48
103 expect resp.http.X-Cache-Hit == 0
104 expect resp.http.X-Cache-Name == ""
105
106 txreq -url "/nocache"
107 rxresp
108 expect resp.status == 200
109 expect resp.bodylen == 51
110 expect resp.http.X-Cache-Hit == 0
111 expect resp.http.X-Cache-Name == ""
112
113 # Response should come form the cache now
114 txreq -url "/nocache"
115 rxresp
116 expect resp.status == 200
117 expect resp.bodylen == 51
118 expect resp.http.X-Cache-Hit == 0
119 expect resp.http.X-Cache-Name == ""
120
121 txreq -url "/first"
122 rxresp
123 expect resp.status == 200
124 expect resp.bodylen == 45
125 expect resp.http.X-Cache-Hit == 1
126 expect resp.http.X-Cache-Name == "first_cache"
127
128 txreq -url "/second"
129 rxresp
130 expect resp.status == 200
131 expect resp.bodylen == 48
132 expect resp.http.X-Cache-Hit == 1
133 expect resp.http.X-Cache-Name == "second_cache"
134} -run