Mercurial > hg > nginx-tests
comparison h2.t @ 745:cdd3659d1144
Tests: simple HTTP/2 test for request body in multiple DATA frames.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 19 Oct 2015 20:43:22 +0300 |
parents | 51a413e673d6 |
children | b818ea3a73de |
comparison
equal
deleted
inserted
replaced
744:51a413e673d6 | 745:cdd3659d1144 |
---|---|
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(232); | 35 ->has_daemon('openssl')->plan(233); |
36 | 36 |
37 # Some systems have a bug in not treating zero writev iovcnt as EINVAL | 37 # Some systems have a bug in not treating zero writev iovcnt as EINVAL |
38 | 38 |
39 $t->todo_alerts() if $^O eq 'darwin'; | 39 $t->todo_alerts() if $^O eq 'darwin'; |
40 | 40 |
1295 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | 1295 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); |
1296 | 1296 |
1297 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | 1297 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
1298 is($frame->{headers}->{':status'}, '200', 'request body with padding - next'); | 1298 is($frame->{headers}->{':status'}, '200', 'request body with padding - next'); |
1299 | 1299 |
1300 # request body sent in multiple DATA frames (uses proxied response) | |
1301 | |
1302 $sess = new_session(); | |
1303 $sid = new_stream($sess, | |
1304 { path => '/proxy2/t2.html', body => 'TEST', body_split => [2] }); | |
1305 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
1306 | |
1307 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
1308 is($frame->{headers}->{'x-body'}, 'TEST', 'request body in multiple frames'); | |
1309 | |
1300 # initial window size, client side | 1310 # initial window size, client side |
1301 | 1311 |
1302 # 6.9.2. Initial Flow-Control Window Size | 1312 # 6.9.2. Initial Flow-Control Window Size |
1303 # When an HTTP/2 connection is first established, new streams are | 1313 # When an HTTP/2 connection is first established, new streams are |
1304 # created with an initial flow-control window size of 65,535 octets. | 1314 # created with an initial flow-control window size of 65,535 octets. |
2330 my $headers = $uri->{headers}; | 2340 my $headers = $uri->{headers}; |
2331 my $body = $uri->{body}; | 2341 my $body = $uri->{body}; |
2332 my $prio = $uri->{prio}; | 2342 my $prio = $uri->{prio}; |
2333 my $dep = $uri->{dep}; | 2343 my $dep = $uri->{dep}; |
2334 my $split = ref $uri->{continuation} && $uri->{continuation} || []; | 2344 my $split = ref $uri->{continuation} && $uri->{continuation} || []; |
2345 my $bsplit = ref $uri->{body_split} && $uri->{body_split} || []; | |
2335 | 2346 |
2336 my $pad = defined $uri->{padding} ? $uri->{padding} : 0; | 2347 my $pad = defined $uri->{padding} ? $uri->{padding} : 0; |
2337 my $padlen = defined $uri->{padding} ? 1 : 0; | 2348 my $padlen = defined $uri->{padding} ? 1 : 0; |
2338 my $bpad = defined $uri->{body_padding} ? $uri->{body_padding} : 0; | 2349 my $bpad = defined $uri->{body_padding} ? $uri->{body_padding} : 0; |
2339 my $bpadlen = defined $uri->{body_padding} ? 1 : 0; | 2350 my $bpadlen = defined $uri->{body_padding} ? 1 : 0; |
2397 $buf .= pack("CC", 0x9, $flags); | 2408 $buf .= pack("CC", 0x9, $flags); |
2398 $buf .= pack("N", $ctx->{last_stream}); | 2409 $buf .= pack("N", $ctx->{last_stream}); |
2399 $buf .= $input; | 2410 $buf .= $input; |
2400 } | 2411 } |
2401 | 2412 |
2402 if (defined $body) { | 2413 my @body = map { substr $body, 0, $_, "" } @$bsplit; |
2403 $buf .= pack_length(length($body) + $bpad + $bpadlen); | 2414 push @body, $body; |
2404 my $flags = $bpadlen ? 0x8 : 0x0; | 2415 |
2405 $buf .= pack 'CC', 0x0, 0x1 | $flags; # DATA, END_STREAM | 2416 if (defined $body[0]) { |
2417 $buf .= pack_length(length($body[0]) + $bpad + $bpadlen); | |
2418 my $flags = defined $uri->{body_split} ? 0x0 : 0x1; | |
2419 $flags |= 0x8 if $bpadlen; | |
2420 $buf .= pack 'CC', 0x0, $flags; # DATA, END_STREAM | |
2406 $buf .= pack 'N', $ctx->{last_stream}; | 2421 $buf .= pack 'N', $ctx->{last_stream}; |
2407 $buf .= pack 'C', $bpad if $bpadlen; # DATA Pad Length? | 2422 $buf .= pack 'C', $bpad if $bpadlen; # DATA Pad Length? |
2423 $buf .= $body[0]; | |
2424 $buf .= (pack 'C', 0) x $bpad if $bpadlen; # DATA Padding | |
2425 } | |
2426 | |
2427 shift @body; | |
2428 | |
2429 while (@body) { | |
2430 $body = shift @body; | |
2431 $buf .= pack_length(length($body) + $bpad + $bpadlen); | |
2432 my $flags = @body ? 0x0 : 0x1; | |
2433 $flags |= 0x8 if $bpadlen; | |
2434 $buf .= pack 'CC', 0x0, $flags; | |
2435 $buf .= pack 'N', $ctx->{last_stream}; | |
2436 $buf .= pack 'C', $bpad if $bpadlen; | |
2408 $buf .= $body; | 2437 $buf .= $body; |
2409 $buf .= (pack 'C', 0) x $bpad if $bpadlen; # DATA Padding | 2438 $buf .= (pack 'C', 0) x $bpad if $bpadlen; # DATA Padding |
2410 } | 2439 } |
2411 | 2440 |
2412 $split = ref $uri->{split} && $uri->{split} || []; | 2441 $split = ref $uri->{split} && $uri->{split} || []; |