Mercurial > hg > nginx-tests
comparison proxy_cache_revalidate.t @ 530:a61571a5f8df
Tests: conditional requests only for cached 200/206 responses.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 03 Mar 2015 21:04:51 +0300 |
parents | b86c05516e65 |
children | 679a7669ee71 |
comparison
equal
deleted
inserted
replaced
529:42810c40ebb8 | 530:a61571a5f8df |
---|---|
21 select STDERR; $| = 1; | 21 select STDERR; $| = 1; |
22 select STDOUT; $| = 1; | 22 select STDOUT; $| = 1; |
23 | 23 |
24 plan(skip_all => 'win32') if $^O eq 'MSWin32'; | 24 plan(skip_all => 'win32') if $^O eq 'MSWin32'; |
25 | 25 |
26 my $t = Test::Nginx->new()->has(qw/http proxy cache/) | 26 my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite/) |
27 ->write_file_expand('nginx.conf', <<'EOF'); | 27 ->write_file_expand('nginx.conf', <<'EOF'); |
28 | 28 |
29 %%TEST_GLOBALS%% | 29 %%TEST_GLOBALS%% |
30 | 30 |
31 daemon off; | 31 daemon off; |
62 location / { } | 62 location / { } |
63 location /etag/ { | 63 location /etag/ { |
64 proxy_pass http://127.0.0.1:8081/; | 64 proxy_pass http://127.0.0.1:8081/; |
65 proxy_hide_header Last-Modified; | 65 proxy_hide_header Last-Modified; |
66 } | 66 } |
67 location /201 { | |
68 add_header Last-Modified "Mon, 02 Mar 2015 17:20:58 GMT"; | |
69 add_header Cache-Control "max-age=1"; | |
70 add_header X-If-Modified-Since $http_if_modified_since; | |
71 return 201; | |
72 } | |
67 } | 73 } |
68 } | 74 } |
69 | 75 |
70 EOF | 76 EOF |
71 | 77 |
72 $t->write_file('t', 'SEE-THIS'); | 78 $t->write_file('t', 'SEE-THIS'); |
73 $t->write_file('t2', 'SEE-THIS'); | 79 $t->write_file('t2', 'SEE-THIS'); |
74 | 80 |
75 $t->run()->plan(17); | 81 $t->run()->plan(20); |
76 | 82 |
77 ############################################################################### | 83 ############################################################################### |
78 | 84 |
79 # request documents and make sure they are cached | 85 # request documents and make sure they are cached |
80 | 86 |
87 like(http_get('/etag/t'), qr/X-Cache-Status: MISS.*SEE/ms, 'etag'); | 93 like(http_get('/etag/t'), qr/X-Cache-Status: MISS.*SEE/ms, 'etag'); |
88 like(http_get('/etag/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'etag cached'); | 94 like(http_get('/etag/t'), qr/X-Cache-Status: HIT.*SEE/ms, 'etag cached'); |
89 | 95 |
90 like(http_get('/etag/t2'), qr/X-Cache-Status: MISS.*SEE/ms, 'etag2'); | 96 like(http_get('/etag/t2'), qr/X-Cache-Status: MISS.*SEE/ms, 'etag2'); |
91 like(http_get('/etag/t2'), qr/X-Cache-Status: HIT.*SEE/ms, 'etag2 cached'); | 97 like(http_get('/etag/t2'), qr/X-Cache-Status: HIT.*SEE/ms, 'etag2 cached'); |
98 | |
99 like(http_get('/201'), qr/X-Cache-Status: MISS/, 'other status'); | |
100 like(http_get('/201'), qr/X-Cache-Status: HIT/, 'other status cached'); | |
92 | 101 |
93 # wait for a while for cached responses to expire | 102 # wait for a while for cached responses to expire |
94 | 103 |
95 select undef, undef, undef, 2.5; | 104 select undef, undef, undef, 2.5; |
96 | 105 |
126 like(http_get('/etag/t2'), qr/X-Cache-Status: EXPIRED.*NEW/ms, | 135 like(http_get('/etag/t2'), qr/X-Cache-Status: EXPIRED.*NEW/ms, |
127 'etag2 revalidate failed'); | 136 'etag2 revalidate failed'); |
128 like(http_get('/etag/t2'), qr/X-Cache-Status: HIT.*NEW/ms, | 137 like(http_get('/etag/t2'), qr/X-Cache-Status: HIT.*NEW/ms, |
129 'etag2 new response cached'); | 138 'etag2 new response cached'); |
130 | 139 |
140 # check that conditional requests are only used for 200/206 responses | |
141 | |
142 # d0ce06cb9be1 in 1.7.3 changed to ignore header filter's work to strip | |
143 # the Last-Modified header when storing non-200/206 in cache; | |
144 # 1573fc7875fa in 1.7.9 effectively turned it back. | |
145 | |
146 unlike(http_get('/201'), qr/X-If-Modified/, 'other status no revalidation'); | |
147 | |
131 ############################################################################### | 148 ############################################################################### |