comparison proxy-cache.t @ 140:3f246a1be2b0

Tests: unfinished responses shouldn't be cached.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 19 Jul 2010 04:55:06 +0400
parents 8ac1faaddd2c
children 2ea7cd95ff05
comparison
equal deleted inserted replaced
139:8b62dd9b8615 140:3f246a1be2b0
19 ############################################################################### 19 ###############################################################################
20 20
21 select STDERR; $| = 1; 21 select STDERR; $| = 1;
22 select STDOUT; $| = 1; 22 select STDOUT; $| = 1;
23 23
24 my $t = Test::Nginx->new()->has(qw/http proxy cache gzip/)->plan(9) 24 my $t = Test::Nginx->new()->has(qw/http proxy cache gzip/)->plan(10)
25 ->write_file_expand('nginx.conf', <<'EOF'); 25 ->write_file_expand('nginx.conf', <<'EOF');
26 26
27 %%TEST_GLOBALS%% 27 %%TEST_GLOBALS%%
28 28
29 master_process off; 29 master_process off;
57 proxy_cache_min_uses 1; 57 proxy_cache_min_uses 1;
58 58
59 proxy_cache_use_stale error timeout invalid_header http_500 59 proxy_cache_use_stale error timeout invalid_header http_500
60 http_404; 60 http_404;
61 } 61 }
62
63 location /fake/ {
64 proxy_pass http://127.0.0.1:8082;
65 proxy_cache NAME;
66 }
62 } 67 }
63 server { 68 server {
64 listen 127.0.0.1:8081; 69 listen 127.0.0.1:8081;
65 server_name localhost; 70 server_name localhost;
66 71
72 EOF 77 EOF
73 78
74 $t->write_file('t.html', 'SEE-THIS'); 79 $t->write_file('t.html', 'SEE-THIS');
75 $t->write_file('t2.html', 'SEE-THIS'); 80 $t->write_file('t2.html', 'SEE-THIS');
76 $t->write_file('empty.html', ''); 81 $t->write_file('empty.html', '');
82 $t->run_daemon(\&http_fake_daemon);
77 $t->run(); 83 $t->run();
78 84
79 ############################################################################### 85 ###############################################################################
80 86
81 like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request'); 87 like(http_get('/t.html'), qr/SEE-THIS/, 'proxy request');
107 like(http_gzip_request('/empty.html'), 113 like(http_gzip_request('/empty.html'),
108 qr/HTTP.*14\x0d\x0a.{20}\x0d\x0a0\x0d\x0a\x0d\x0a\z/s, 114 qr/HTTP.*14\x0d\x0a.{20}\x0d\x0a0\x0d\x0a\x0d\x0a\z/s,
109 'empty get stale'); 115 'empty get stale');
110 } 116 }
111 117
118 {
119 local $TODO = 'patch pending';
120
121 http_get('/fake/unfinished');
122 like(http_get('/fake/unfinished'), qr/unfinished 2/, 'unfinished not cached');
123 }
124
112 ############################################################################### 125 ###############################################################################
126
127 sub http_fake_daemon {
128 my $server = IO::Socket::INET->new(
129 Proto => 'tcp',
130 LocalAddr => '127.0.0.1:8082',
131 Listen => 5,
132 Reuse => 1
133 )
134 or die "Can't create listening socket: $!\n";
135
136 my $num = 0;
137
138 while (my $client = $server->accept()) {
139 $client->autoflush(1);
140
141 while (<$client>) {
142 last if (/^\x0d?\x0a?$/);
143 }
144
145 $num++;
146 print $client <<"EOF";
147 HTTP/1.1 200 OK
148 Content-Length: 100
149 Cache-Control: max-age=300
150 Connection: close
151
152 unfinished $num
153 EOF
154 }
155 }
156
157 ###############################################################################