Mercurial > hg > nginx-tests
comparison h2.t @ 650:8a2cf558b8ae
Tests: HTTP/2 tests for $http2 variable.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 18 Aug 2015 16:54:41 +0300 |
parents | 4e36550410b3 |
children | 9f66f0029dca |
comparison
equal
deleted
inserted
replaced
649:17ddc69fd9b3 | 650:8a2cf558b8ae |
---|---|
23 ############################################################################### | 23 ############################################################################### |
24 | 24 |
25 select STDERR; $| = 1; | 25 select STDERR; $| = 1; |
26 select STDOUT; $| = 1; | 26 select STDOUT; $| = 1; |
27 | 27 |
28 eval { require IO::Socket::SSL; }; | |
29 plan(skip_all => 'IO::Socket::SSL not installed') if $@; | |
30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; | |
31 plan(skip_all => 'IO::Socket::SSL too old') if $@; | |
32 | |
28 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/) |
29 ->has(qw/limit_conn rewrite realip shmem/)->plan(139); | 34 ->has(qw/limit_conn rewrite realip shmem/) |
35 ->has_daemon('openssl')->plan(142); | |
30 | 36 |
31 $t->write_file_expand('nginx.conf', <<'EOF'); | 37 $t->write_file_expand('nginx.conf', <<'EOF'); |
32 | 38 |
33 %%TEST_GLOBALS%% | 39 %%TEST_GLOBALS%% |
34 | 40 |
73 location /pp { | 79 location /pp { |
74 set_real_ip_from 127.0.0.1/32; | 80 set_real_ip_from 127.0.0.1/32; |
75 real_ip_header proxy_protocol; | 81 real_ip_header proxy_protocol; |
76 alias %%TESTDIR%%/t2.html; | 82 alias %%TESTDIR%%/t2.html; |
77 add_header X-PP $remote_addr; | 83 add_header X-PP $remote_addr; |
84 } | |
85 location /h2 { | |
86 return 200 $http2; | |
78 } | 87 } |
79 location /redirect { | 88 location /redirect { |
80 error_page 405 /; | 89 error_page 405 /; |
81 return 405; | 90 return 405; |
82 } | 91 } |
518 | 527 |
519 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | 528 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
520 is($frame->{length}, 10, 'range - DATA length'); | 529 is($frame->{length}, 10, 'range - DATA length'); |
521 is($frame->{data}, '002XXXX000', 'range - DATA payload'); | 530 is($frame->{data}, '002XXXX000', 'range - DATA payload'); |
522 | 531 |
532 # $http2 | |
533 | |
534 $sess = new_session(); | |
535 $sid = new_stream($sess, { path => '/h2' }); | |
536 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
537 | |
538 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
539 is($frame->{data}, 'h2c', 'http variable - h2c'); | |
540 | |
541 # SSL/TLS connection, NPN | |
542 | |
543 SKIP: { | |
544 eval { IO::Socket::SSL->can_npn() or die; }; | |
545 skip 'OpenSSL NPN support required', 1 if $@; | |
546 | |
547 $sess = new_session(8084, SSL => 1, npn => 'h2'); | |
548 $sid = new_stream($sess, { path => '/h2' }); | |
549 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
550 | |
551 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
552 is($frame->{data}, 'h2', 'http variable - npn'); | |
553 | |
554 } | |
555 | |
556 # SSL/TLS connection, ALPN | |
557 | |
558 SKIP: { | |
559 eval { IO::Socket::SSL->can_alpn() or die; }; | |
560 skip 'OpenSSL ALPN support required', 1 if $@; | |
561 | |
562 $sess = new_session(8084, SSL => 1, alpn => 'h2'); | |
563 $sid = new_stream($sess, { path => '/h2' }); | |
564 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
565 | |
566 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
567 is($frame->{data}, 'h2', 'http variable - alpn'); | |
568 | |
569 } | |
570 | |
523 # CONTINUATION | 571 # CONTINUATION |
524 | 572 |
573 $sess = new_session(); | |
525 $sid = new_stream($sess, { continuation => 1, headers => [ | 574 $sid = new_stream($sess, { continuation => 1, headers => [ |
526 { name => ':method', value => 'HEAD', mode => 1 }, | 575 { name => ':method', value => 'HEAD', mode => 1 }, |
527 { name => ':scheme', value => 'http', mode => 0 }, | 576 { name => ':scheme', value => 'http', mode => 0 }, |
528 { name => ':path', value => '/', mode => 0 }]}); | 577 { name => ':path', value => '/', mode => 0 }]}); |
529 h2_continue($sess, $sid, { continuation => 1, headers => [ | 578 h2_continue($sess, $sid, { continuation => 1, headers => [ |
1635 sub raw_read { | 1684 sub raw_read { |
1636 my ($s, $buf, $len) = @_; | 1685 my ($s, $buf, $len) = @_; |
1637 my $got = ''; | 1686 my $got = ''; |
1638 | 1687 |
1639 while (length($buf) < $len && IO::Select->new($s)->can_read(1)) { | 1688 while (length($buf) < $len && IO::Select->new($s)->can_read(1)) { |
1640 $s->sysread($got, $len - length($buf)) or last; | 1689 $s->sysread($got, 16384) or last; |
1641 log_in($got); | 1690 log_in($got); |
1642 $buf .= $got; | 1691 $buf .= $got; |
1643 } | 1692 } |
1644 return $buf; | 1693 return $buf; |
1645 } | 1694 } |
1660 | 1709 |
1661 sub new_session { | 1710 sub new_session { |
1662 my ($port, %extra) = @_; | 1711 my ($port, %extra) = @_; |
1663 my ($s); | 1712 my ($s); |
1664 | 1713 |
1665 $s = new_socket($port); | 1714 $s = new_socket($port, %extra); |
1666 | 1715 |
1667 if ($extra{proxy}) { | 1716 if ($extra{proxy}) { |
1668 raw_write($s, $extra{proxy}); | 1717 raw_write($s, $extra{proxy}); |
1669 } | 1718 } |
1670 | 1719 |
1677 dynamic_decode => [ static_table() ], | 1726 dynamic_decode => [ static_table() ], |
1678 static_table_size => scalar @{[static_table()]} }; | 1727 static_table_size => scalar @{[static_table()]} }; |
1679 } | 1728 } |
1680 | 1729 |
1681 sub new_socket { | 1730 sub new_socket { |
1682 my ($port) = @_; | 1731 my ($port, %extra) = @_; |
1732 my $npn = $extra{'npn'}; | |
1733 my $alpn = $extra{'alpn'}; | |
1683 my $s; | 1734 my $s; |
1684 | 1735 |
1685 $port = 8080 unless defined $port; | 1736 $port = 8080 unless defined $port; |
1686 | 1737 |
1687 eval { | 1738 eval { |
1690 alarm(2); | 1741 alarm(2); |
1691 $s = IO::Socket::INET->new( | 1742 $s = IO::Socket::INET->new( |
1692 Proto => 'tcp', | 1743 Proto => 'tcp', |
1693 PeerAddr => "127.0.0.1:$port", | 1744 PeerAddr => "127.0.0.1:$port", |
1694 ); | 1745 ); |
1746 IO::Socket::SSL->start_SSL($s, | |
1747 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(), | |
1748 SSL_npn_protocols => $npn ? [ $npn ] : undef, | |
1749 SSL_alpn_protocols => $alpn ? [ $alpn ] : undef, | |
1750 SSL_error_trap => sub { die $_[1] } | |
1751 ) if $extra{'SSL'}; | |
1695 alarm(0); | 1752 alarm(0); |
1696 }; | 1753 }; |
1697 alarm(0); | 1754 alarm(0); |
1698 | 1755 |
1699 if ($@) { | 1756 if ($@) { |