comparison spdy.t @ 428:e95c3340d94a

Tests: more SPDY tests for caching HEAD requests. It is explicitly checked that SYN_REPLY is not followed by DATA, also with proxy_buffering off.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 04 Jul 2014 13:19:13 +0400
parents daea9cf92c14
children 89f7a882d692
comparison
equal deleted inserted replaced
427:daea9cf92c14 428:e95c3340d94a
36 plan(skip_all => 'win32') if $^O eq 'MSWin32'; 36 plan(skip_all => 'win32') if $^O eq 'MSWin32';
37 37
38 my $t = Test::Nginx->new() 38 my $t = Test::Nginx->new()
39 ->has(qw/http proxy cache limit_conn rewrite spdy realip/); 39 ->has(qw/http proxy cache limit_conn rewrite spdy realip/);
40 40
41 $t->plan(74)->write_file_expand('nginx.conf', <<'EOF'); 41 $t->plan(76)->write_file_expand('nginx.conf', <<'EOF');
42 42
43 %%TEST_GLOBALS%% 43 %%TEST_GLOBALS%%
44 44
45 daemon off; 45 daemon off;
46 46
87 add_header X-Body "$request_body"; 87 add_header X-Body "$request_body";
88 proxy_pass http://127.0.0.1:8081/; 88 proxy_pass http://127.0.0.1:8081/;
89 proxy_cache NAME; 89 proxy_cache NAME;
90 proxy_cache_valid 1m; 90 proxy_cache_valid 1m;
91 } 91 }
92 location /proxy_buffering_off {
93 proxy_pass http://127.0.0.1:8081/;
94 proxy_cache NAME;
95 proxy_cache_valid 1m;
96 proxy_buffering off;
97 }
92 location /t3.html { 98 location /t3.html {
93 limit_conn conn 1; 99 limit_conn conn 1;
94 } 100 }
95 } 101 }
96 } 102 }
234 240
235 ($frame) = grep { $_->{type} eq "DATA" } @$frames; 241 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
236 ok($frame, 'DATA frame with redirect'); 242 ok($frame, 'DATA frame with redirect');
237 is($frame->{data}, 'body', 'DATA payload with redirect'); 243 is($frame->{data}, 'body', 'DATA payload with redirect');
238 244
245 # SYN_REPLY could be received with fin, followed by DATA
246
247 $sess = new_session();
248 $sid1 = spdy_stream($sess, { path => '/proxy/t2.html', method => 'HEAD' });
249
250 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
251 push @$frames, $_ for @{spdy_read($sess, all => [{ sid => $sid1 }])};
252 ok(!grep ({ $_->{type} eq "DATA" } @$frames), 'proxy cache HEAD - no body');
253
239 # ensure that HEAD-like requests, i.e., without response body, do not lead to 254 # ensure that HEAD-like requests, i.e., without response body, do not lead to
240 # client connection close due to cache filling up with upstream response body 255 # client connection close due to cache filling up with upstream response body
241 256
242 TODO: { 257 TODO: {
243 local $TODO = 'premature client connection close'; 258 local $TODO = 'premature client connection close';
244 259
245 $sess = new_session();
246 $sid1 = spdy_stream($sess, { path => '/proxy/t2.html', method => 'HEAD' });
247 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
248
249 $sid2 = spdy_stream($sess, { path => '/' }); 260 $sid2 = spdy_stream($sess, { path => '/' });
250 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]); 261 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
251 ok(grep ({ $_->{type} eq "SYN_REPLY" } @$frames), 'proxy cache headers only'); 262 ok(grep ({ $_->{type} eq "SYN_REPLY" } @$frames), 'proxy cache headers only');
252 263
253 } 264 }
265
266 # HEAD on empty cache with proxy_buffering off
267
268 $sess = new_session();
269 $sid1 = spdy_stream($sess,
270 { path => '/proxy_buffering_off/t2.html?1', method => 'HEAD' });
271
272 $frames = spdy_read($sess, all => [{ sid => $sid1, fin => 1 }]);
273 push @$frames, $_ for @{spdy_read($sess, all => [{ sid => $sid1 }])};
274 ok(!grep ({ $_->{type} eq "DATA" } @$frames),
275 'proxy cache HEAD buffering off - no body');
254 276
255 # simple proxy cache test 277 # simple proxy cache test
256 278
257 $sess = new_session(); 279 $sess = new_session();
258 $sid1 = spdy_stream($sess, { path => '/proxy/t2.html' }); 280 $sid1 = spdy_stream($sess, { path => '/proxy/t2.html' });