Mercurial > hg > nginx-tests
annotate proxy_cache_use_stale.t @ 1134:d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 20 Feb 2017 18:49:12 +0300 |
parents | |
children | 129b9e4ca3b3 |
rev | line source |
---|---|
1134
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http proxy cache, proxy_cache_use_stale. |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx qw/ :DEFAULT http_end /; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite limit_req/) |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 http { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 proxy_cache_path %%TESTDIR%%/cache levels=1:2 keys_zone=NAME:1m; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 limit_req_zone $binary_remote_addr zone=one:1m rate=15r/m; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 listen 127.0.0.1:8080; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server_name localhost; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 location / { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 proxy_pass http://127.0.0.1:8081; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 proxy_cache NAME; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 proxy_cache_key $uri; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 proxy_cache_revalidate on; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_cache_background_update on; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 add_header X-Cache-Status $upstream_cache_status; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 location /t4.html { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 proxy_pass http://127.0.0.1:8081/t.html; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 proxy_cache_revalidate off; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 location /t5.html { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 proxy_pass http://127.0.0.1:8081/t.html; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 proxy_cache_background_update off; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 location /updating/ { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 proxy_pass http://127.0.0.1:8081/; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 proxy_cache_use_stale updating; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 location /t8.html { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 proxy_pass http://127.0.0.1:8081/t.html; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 proxy_cache_valid 1s; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 server { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 listen 127.0.0.1:8081; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 server_name localhost; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 add_header Cache-Control $http_x_cache_control; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 if ($arg_e) { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 return 500; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 location / { } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 location /t6.html { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 limit_req zone=one burst=2; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 EOF |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 $t->write_file('t.html', 'SEE-THIS'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 $t->write_file('tt.html', 'SEE-THIS'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 $t->write_file('t2.html', 'SEE-THIS'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 $t->write_file('t3.html', 'SEE-THIS'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 $t->write_file('t6.html', 'SEE-THIS'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 $t->try_run('no proxy_cache_background_update')->plan(25); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 ############################################################################### |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 like(get('/t.html', 'max-age=1, stale-if-error=5'), qr/MISS/, 'stale-if-error'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 like(http_get('/t.html?e=1'), qr/HIT/, 's-i-e - cached'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 like(get('/t2.html', 'max-age=1, stale-while-revalidate=10'), qr/MISS/, |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 'stale-while-revalidate'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 like(http_get('/t2.html'), qr/HIT/, 's-w-r - cached'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 get('/tt.html', 'max-age=1, stale-if-error=2'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 get('/t3.html', 'max-age=1, stale-while-revalidate=2'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 get('/t4.html', 'max-age=1, stale-while-revalidate=2'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 get('/t5.html', 'max-age=1, stale-while-revalidate=2'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 get('/t6.html', 'max-age=1, stale-while-revalidate=2'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
126 get('/updating/t.html', 'max-age=1'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 get('/updating/t2.html', 'max-age=1, stale-while-revalidate=2'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
128 get('/t8.html', 'stale-while-revalidate=10'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
129 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
130 sleep 2; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
131 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
132 like(http_get('/t.html?e=1'), qr/STALE/, 's-i-e - stale'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 like(http_get('/tt.html?e=1'), qr/STALE/, 's-i-e - stale 2'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 like(http_get('/t.html'), qr/REVALIDATED/, 's-i-e - revalidated'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
136 like(http_get('/t2.html?e=1'), qr/STALE/, 's-w-r - revalidate error'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
137 like(http_get('/t2.html'), qr/STALE/, 's-w-r - stale while revalidate'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 like(http_get('/t2.html'), qr/HIT/, 's-w-r - revalidated'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 like(get('/t4.html', 'max-age=1, stale-while-revalidate=2'), qr/STALE/, |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
141 's-w-r - unconditional revalidate'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
142 like(http_get('/t4.html'), qr/HIT/, 's-w-r - unconditional revalidated'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 like(http_get('/t5.html?e=1'), qr/STALE/, |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 's-w-r - foreground revalidate error'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
146 like(http_get('/t5.html'), qr/REVALIDATED/, 's-w-r - foreground revalidated'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
147 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
148 # UPDATING while s–w-r |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
149 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
150 $t->write_file('t6.html', 'SEE-THAT'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 my $s = get('/t6.html', 'max-age=1, stale-while-revalidate=2', start => 1); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
153 like(http_get('/t6.html'), qr/UPDATING.*SEE-THIS/s, 's-w-r - updating'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 like(http_end($s), qr/STALE.*SEE-THIS/s, 's-w-r - updating stale'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 like(http_get('/t6.html'), qr/HIT.*SEE-THAT/s, 's-w-r - updating revalidated'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 # stale-while-revalidate with proxy_cache_use_stale updating |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 like(http_get('/updating/t.html'), qr/STALE/, |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 's-w-r - use_stale updating stale'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 like(http_get('/updating/t.html'), qr/HIT/, |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 's-w-r - use_stale updating revalidated'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 # stale-while-revalidate with proxy_cache_valid |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 like(http_get('/t8.html'), qr/STALE/, 's-w-r - proxy_cache_valid revalidate'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 like(http_get('/t8.html'), qr/HIT/, 's-w-r - proxy_cache_valid revalidated'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
169 sleep 2; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
170 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 like(http_get('/t2.html?e=1'), qr/STALE/, 's-w-r - stale after revalidate'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 like(http_get('/t3.html?e=1'), qr/ 500 /, 's-w-r - ceased'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 like(http_get('/tt.html?e=1'), qr/ 500 /, 's-i-e - ceased'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 like(http_get('/updating/t2.html'), qr/STALE/, |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 's-w-r - overriden with use_stale updating'); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
177 ############################################################################### |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 sub get { |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 my ($url, $extra, %extra) = @_; |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 return http(<<EOF, %extra); |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
182 GET $url HTTP/1.1 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
183 Host: localhost |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
184 Connection: close |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
185 X-Cache-Control: $extra |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
186 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
187 EOF |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
188 } |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
189 |
d77c331affff
Tests: proxy_cache_use_stale tests with Cache-Control in response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
190 ############################################################################### |