comparison proxy_cache_valid.t @ 1225:66426ca24671

Tests: intercepted errors with cache control (ticket #1382).
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 04 Oct 2017 15:44:52 +0300
parents bd1cf0a80b28
children 97c8280de681
comparison
equal deleted inserted replaced
1224:2ec9ce1bc820 1225:66426ca24671
21 ############################################################################### 21 ###############################################################################
22 22
23 select STDERR; $| = 1; 23 select STDERR; $| = 1;
24 select STDOUT; $| = 1; 24 select STDOUT; $| = 1;
25 25
26 my $t = Test::Nginx->new()->has(qw/http proxy cache/)->plan(8) 26 my $t = Test::Nginx->new()->has(qw/http proxy cache rewrite/)->plan(12)
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;
45 45
46 location / { 46 location / {
47 proxy_pass http://127.0.0.1:8081; 47 proxy_pass http://127.0.0.1:8081;
48 proxy_cache NAME; 48 proxy_cache NAME;
49 49
50 proxy_cache_valid 1m; 50 proxy_cache_valid 200 401 1m;
51
52 proxy_intercept_errors on;
53 error_page 404 401 = @fallback;
51 54
52 add_header X-Cache-Status $upstream_cache_status; 55 add_header X-Cache-Status $upstream_cache_status;
53 } 56 }
57
58 location @fallback {
59 return 403;
60 }
54 } 61 }
62
55 server { 63 server {
56 listen 127.0.0.1:8081; 64 listen 127.0.0.1:8081;
57 server_name localhost; 65 server_name localhost;
58 66
59 location / { 67 location / {
60 add_header Cache-Control $http_x_cc; 68 add_header Cache-Control $http_x_cc always;
69 error_page 403 = /index-no-cache;
70 }
71
72 location /index-no-cache {
73 add_header Cache-Control no-cache always;
74 return 401;
61 } 75 }
62 } 76 }
63 } 77 }
64 78
65 EOF 79 EOF
84 # Cache-Control in the response header overrides proxy_cache_valid 98 # Cache-Control in the response header overrides proxy_cache_valid
85 99
86 like(http_get('/t.html?1'), qr/EXPIRED/, 'max-age ceased'); 100 like(http_get('/t.html?1'), qr/EXPIRED/, 'max-age ceased');
87 like(http_get('/t.html?2'), qr/HIT/, 's-maxage overrides max-age'); 101 like(http_get('/t.html?2'), qr/HIT/, 's-maxage overrides max-age');
88 102
103 # ticket #1382, cache item "error" field was not set from Cache-Control: max-age
104
105 like(get('/t2.html', 'X-CC: max-age=1'), qr/403 Forbidden/, 'intercept error');
106
107 $t->write_file('t2.html', 'NOOP');
108
109 TODO: {
110 local $TODO = 'not yet' unless $t->has_version('1.13.6');
111
112 like(http_get('/t2.html'), qr/403 Forbidden/, 'error cached from max-age');
113
114 }
115
116 # ticket #1382, cache item "error" field was set regardless of u->cacheable.
117
118 like(http_get('/'), qr/403 Forbidden/, 'error no-cache');
119
120 $t->write_file('index.html', '');
121
122 TODO: {
123 local $TODO = 'not yet' unless $t->has_version('1.13.6');
124
125 like(http_get('/'), qr/200 OK/, 'error no-cache - not cacheable');
126
127 }
128
89 ############################################################################### 129 ###############################################################################
90 130
91 sub get { 131 sub get {
92 my ($url, $extra) = @_; 132 my ($url, $extra) = @_;
93 return http(<<EOF); 133 return http(<<EOF);