Mercurial > hg > nginx-tests
comparison h2_headers.t @ 1169:518d1c865812
Tests: avoid illegal dereference on errors in h2_headers.t.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 03 May 2017 13:36:40 +0300 |
parents | e2adef0c3faa |
children | 0a7d942d549b |
comparison
equal
deleted
inserted
replaced
1168:8821e405b91e | 1169:518d1c865812 |
---|---|
24 ############################################################################### | 24 ############################################################################### |
25 | 25 |
26 select STDERR; $| = 1; | 26 select STDERR; $| = 1; |
27 select STDOUT; $| = 1; | 27 select STDOUT; $| = 1; |
28 | 28 |
29 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite/)->plan(92) | 29 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite/)->plan(93) |
30 ->write_file_expand('nginx.conf', <<'EOF'); | 30 ->write_file_expand('nginx.conf', <<'EOF'); |
31 | 31 |
32 %%TEST_GLOBALS%% | 32 %%TEST_GLOBALS%% |
33 | 33 |
34 daemon off; | 34 daemon off; |
604 $s = Test::Nginx::HTTP2->new(); | 604 $s = Test::Nginx::HTTP2->new(); |
605 $sid = $s->new_stream({ path => '/continuation?h=' . 'x' x 2**13 }); | 605 $sid = $s->new_stream({ path => '/continuation?h=' . 'x' x 2**13 }); |
606 | 606 |
607 $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]); | 607 $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]); |
608 my @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; | 608 my @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; |
609 is(@{$data[-1]->{headers}{'x-longheader'}}, 3, | 609 my $data = $data[-1]; |
610 is(@{$data->{headers}{'x-longheader'}}, 3, | |
610 'response CONTINUATION - headers'); | 611 'response CONTINUATION - headers'); |
611 is($data[-1]->{headers}{'x-longheader'}[0], 'x' x 2**13, | 612 is($data->{headers}{'x-longheader'}[0], 'x' x 2**13, |
612 'response CONTINUATION - header 1'); | 613 'response CONTINUATION - header 1'); |
613 is($data[-1]->{headers}{'x-longheader'}[1], 'x' x 2**13, | 614 is($data->{headers}{'x-longheader'}[1], 'x' x 2**13, |
614 'response CONTINUATION - header 2'); | 615 'response CONTINUATION - header 2'); |
615 is($data[-1]->{headers}{'x-longheader'}[2], 'x' x 2**13, | 616 is($data->{headers}{'x-longheader'}[2], 'x' x 2**13, |
616 'response CONTINUATION - header 3'); | 617 'response CONTINUATION - header 3'); |
617 @data = sort { $a <=> $b } map { $_->{length} } @data; | 618 @data = sort { $a <=> $b } map { $_->{length} } @data; |
618 cmp_ok($data[-1], '<=', 2**14, 'response CONTINUATION - max frame size'); | 619 cmp_ok($data[-1], '<=', 2**14, 'response CONTINUATION - max frame size'); |
619 | 620 |
620 # same but without response DATA frames | 621 # same but without response DATA frames |
622 $s = Test::Nginx::HTTP2->new(); | 623 $s = Test::Nginx::HTTP2->new(); |
623 $sid = $s->new_stream({ path => '/continuation/204?h=' . 'x' x 2**13 }); | 624 $sid = $s->new_stream({ path => '/continuation/204?h=' . 'x' x 2**13 }); |
624 | 625 |
625 $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]); | 626 $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]); |
626 @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; | 627 @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; |
627 is(@{$data[-1]->{headers}{'x-longheader'}}, 3, | 628 $data = $data[-1]; |
629 is(@{$data->{headers}{'x-longheader'}}, 3, | |
628 'no body CONTINUATION - headers'); | 630 'no body CONTINUATION - headers'); |
629 is($data[-1]->{headers}{'x-longheader'}[0], 'x' x 2**13, | 631 is($data->{headers}{'x-longheader'}[0], 'x' x 2**13, |
630 'no body CONTINUATION - header 1'); | 632 'no body CONTINUATION - header 1'); |
631 is($data[-1]->{headers}{'x-longheader'}[1], 'x' x 2**13, | 633 is($data->{headers}{'x-longheader'}[1], 'x' x 2**13, |
632 'no body CONTINUATION - header 2'); | 634 'no body CONTINUATION - header 2'); |
633 is($data[-1]->{headers}{'x-longheader'}[2], 'x' x 2**13, | 635 is($data->{headers}{'x-longheader'}[2], 'x' x 2**13, |
634 'no body CONTINUATION - header 3'); | 636 'no body CONTINUATION - header 3'); |
635 @data = sort { $a <=> $b } map { $_->{length} } @data; | 637 @data = sort { $a <=> $b } map { $_->{length} } @data; |
636 cmp_ok($data[-1], '<=', 2**14, 'no body CONTINUATION - max frame size'); | 638 cmp_ok($data[-1], '<=', 2**14, 'no body CONTINUATION - max frame size'); |
637 | 639 |
638 # response header block is always split by SETTINGS_MAX_FRAME_SIZE | 640 # response header block is always split by SETTINGS_MAX_FRAME_SIZE |
672 $s = Test::Nginx::HTTP2->new(port(8082)); | 674 $s = Test::Nginx::HTTP2->new(port(8082)); |
673 $sid = $s->new_stream({ path => '/continuation?h=' . 'x' x 2**15 }); | 675 $sid = $s->new_stream({ path => '/continuation?h=' . 'x' x 2**15 }); |
674 $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]); | 676 $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]); |
675 | 677 |
676 @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; | 678 @data = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; |
679 ok(@data, 'response header split'); | |
680 | |
681 SKIP: { | |
682 skip 'response header split failed', 2 unless @data; | |
683 | |
677 my ($lengths) = sort { $b <=> $a } map { $_->{length} } @data; | 684 my ($lengths) = sort { $b <=> $a } map { $_->{length} } @data; |
678 cmp_ok($lengths, '<=', 16384, 'response header split - max size'); | 685 cmp_ok($lengths, '<=', 16384, 'response header split - max size'); |
679 | 686 |
680 is(length join('', @{@$frames[-1]->{headers}->{'x-longheader'}}), 98304, | 687 is(length join('', @{$data[-1]->{headers}->{'x-longheader'}}), 98304, |
681 'response header split - headers'); | 688 'response header split - headers'); |
689 | |
690 } | |
682 | 691 |
683 # max_field_size - header field name | 692 # max_field_size - header field name |
684 | 693 |
685 $s = Test::Nginx::HTTP2->new(port(8084)); | 694 $s = Test::Nginx::HTTP2->new(port(8084)); |
686 $sid = $s->new_stream({ headers => [ | 695 $sid = $s->new_stream({ headers => [ |