comparison h2.t @ 845:e31f1b5bb569

Tests: in HTTP/2 tests, read body with $request_body_file. Now that we send request body based on the available send window, it buffers.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 04 Feb 2016 18:05:52 +0300
parents 3a334b20208e
children 9b5e1c5f0240
comparison
equal deleted inserted replaced
844:3a334b20208e 845:e31f1b5bb569
30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; 30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
31 plan(skip_all => 'IO::Socket::SSL too old') if $@; 31 plan(skip_all => 'IO::Socket::SSL too old') if $@;
32 32
33 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/) 33 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/)
34 ->has(qw/limit_conn rewrite realip shmem/) 34 ->has(qw/limit_conn rewrite realip shmem/)
35 ->has_daemon('openssl')->plan(304); 35 ->has_daemon('openssl')->plan(306);
36 36
37 # Some systems may have also a bug in not treating zero writev iovcnt as EINVAL 37 # Some systems may have also a bug in not treating zero writev iovcnt as EINVAL
38 38
39 $t->todo_alerts(); 39 $t->todo_alerts();
40 40
143 proxy_set_header X-Cookie-a $cookie_a; 143 proxy_set_header X-Cookie-a $cookie_a;
144 proxy_set_header X-Cookie-c $cookie_c; 144 proxy_set_header X-Cookie-c $cookie_c;
145 } 145 }
146 location /proxy2/ { 146 location /proxy2/ {
147 add_header X-Body "$request_body"; 147 add_header X-Body "$request_body";
148 add_header X-Body-File $request_body_file;
149 client_body_in_file_only on;
148 proxy_pass http://127.0.0.1:8081/; 150 proxy_pass http://127.0.0.1:8081/;
149 } 151 }
150 location /limit_req { 152 location /limit_req {
151 limit_req zone=req burst=2; 153 limit_req zone=req burst=2;
152 alias %%TESTDIR%%/t2.html; 154 alias %%TESTDIR%%/t2.html;
153 } 155 }
154 location /proxy_limit_req/ { 156 location /proxy_limit_req/ {
155 add_header X-Body $request_body; 157 add_header X-Body $request_body;
158 add_header X-Body-File $request_body_file;
159 client_body_in_file_only on;
156 proxy_pass http://127.0.0.1:8081/; 160 proxy_pass http://127.0.0.1:8081/;
157 limit_req zone=req burst=2; 161 limit_req zone=req burst=2;
158 } 162 }
159 location /cache/ { 163 location /cache/ {
160 proxy_pass http://127.0.0.1:8081/; 164 proxy_pass http://127.0.0.1:8081/;
1417 $sid = new_stream($sess, { path => '/proxy2/t2.html', body_more => 1 }); 1421 $sid = new_stream($sess, { path => '/proxy2/t2.html', body_more => 1 });
1418 h2_body($sess, 'TEST'); 1422 h2_body($sess, 'TEST');
1419 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 1423 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1420 1424
1421 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 1425 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1422 is($frame->{headers}->{'x-body'}, 'TEST', 'request body'); 1426 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST', 'request body');
1423 1427
1424 # request body with padding (uses proxied response) 1428 # request body with padding (uses proxied response)
1425 1429
1426 $sess = new_session(); 1430 $sess = new_session();
1427 $sid = new_stream($sess, { path => '/proxy2/t2.html', body_more => 1 }); 1431 $sid = new_stream($sess, { path => '/proxy2/t2.html', body_more => 1 });
1428 h2_body($sess, 'TEST', { body_padding => 42 }); 1432 h2_body($sess, 'TEST', { body_padding => 42 });
1429 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 1433 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1430 1434
1431 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 1435 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1432 is($frame->{headers}->{'x-body'}, 'TEST', 'request body with padding'); 1436 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST',
1437 'request body with padding');
1433 1438
1434 $sid = new_stream($sess); 1439 $sid = new_stream($sess);
1435 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 1440 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1436 1441
1437 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 1442 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1443 $sid = new_stream($sess, { path => '/proxy2/t2.html', body_more => 1 }); 1448 $sid = new_stream($sess, { path => '/proxy2/t2.html', body_more => 1 });
1444 h2_body($sess, 'TEST', { body_split => [2] }); 1449 h2_body($sess, 'TEST', { body_split => [2] });
1445 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 1450 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1446 1451
1447 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 1452 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1448 is($frame->{headers}->{'x-body'}, 'TEST', 'request body in multiple frames'); 1453 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST',
1454 'request body in multiple frames');
1449 1455
1450 # request body with an empty DATA frame 1456 # request body with an empty DATA frame
1451 # "zero size buf in output" alerts seen 1457 # "zero size buf in output" alerts seen
1452 1458
1453 $sess = new_session(); 1459 $sess = new_session();
1456 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 1462 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1457 1463
1458 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 1464 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1459 is($frame->{headers}->{':status'}, 200, 'request body - empty'); 1465 is($frame->{headers}->{':status'}, 200, 'request body - empty');
1460 1466
1467 TODO: {
1468 local $TODO = 'not yet';
1469
1470 ok($frame->{headers}{'x-body-file'}, 'request body - empty body file');
1471
1472 }
1473
1474 TODO: {
1475 todo_skip 'empty body file', 1 unless $frame->{headers}{'x-body-file'};
1476
1477 is(read_body_file($frame->{headers}{'x-body-file'}), '',
1478 'request body - empty content');
1479
1480 }
1481
1461 # request body delayed in limit_req 1482 # request body delayed in limit_req
1462 1483
1463 $sess = new_session(); 1484 $sess = new_session();
1464 $sid = new_stream($sess, { path => '/proxy_limit_req/', body_more => 1 }); 1485 $sid = new_stream($sess, { path => '/proxy_limit_req/', body_more => 1 });
1465 h2_body($sess, 'TEST'); 1486 h2_body($sess, 'TEST');
1466 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 1487 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1467 1488
1468 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 1489 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1469 is($frame->{headers}->{'x-body'}, 'TEST', 'request body - limit req'); 1490 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST',
1491 'request body - limit req');
1470 1492
1471 # predict send windows 1493 # predict send windows
1472 1494
1473 $sid = new_stream($sess); 1495 $sid = new_stream($sess);
1474 my ($maxwin) = sort {$a <=> $b} $sess->{streams}{$sid}, $sess->{conn_window}; 1496 my ($maxwin) = sort {$a <=> $b} $sess->{streams}{$sid}, $sess->{conn_window};
1481 $sid = new_stream($sess, { path => '/proxy_limit_req/', body => 'TEST2' }); 1503 $sid = new_stream($sess, { path => '/proxy_limit_req/', body => 'TEST2' });
1482 select undef, undef, undef, 1.1; 1504 select undef, undef, undef, 1.1;
1483 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 1505 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
1484 1506
1485 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 1507 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
1486 is($frame->{headers}->{'x-body'}, 'TEST2', 'request body - limit req 2'); 1508 is(read_body_file($frame->{headers}->{'x-body-file'}), 'TEST2',
1509 'request body - limit req 2');
1487 1510
1488 } 1511 }
1489 1512
1490 # partial request body data frame received (to be discarded) within request 1513 # partial request body data frame received (to be discarded) within request
1491 # delayed in limit_req, the rest of data frame is received after response 1514 # delayed in limit_req, the rest of data frame is received after response