annotate h2_ssl.t @ 1788:78fe648d54a7

Tests: avoid send timeout in h2_ssl.t test with canceled streams. While being irrelevant to catching alerts, it slows down run time on systems with short socket buffers.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 30 Aug 2022 17:24:16 +0400
parents 38bd7e75fe69
children cdcd75657e52
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for HTTP/2 protocol with ssl.
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
1788
78fe648d54a7 Tests: avoid send timeout in h2_ssl.t test with canceled streams.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1744
diff changeset
15 use Socket qw/ SOL_SOCKET SO_RCVBUF /;
78fe648d54a7 Tests: avoid send timeout in h2_ssl.t test with canceled streams.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1744
diff changeset
16
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use lib 'lib';
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use Test::Nginx;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 use Test::Nginx::HTTP2;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 ###############################################################################
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 select STDERR; $| = 1;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26 select STDOUT; $| = 1;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2/)
1033
45c80276d691 Tests: unbreak for nginx built with OpenSSL without NPN/ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 997
diff changeset
29 ->has_daemon('openssl');
45c80276d691 Tests: unbreak for nginx built with OpenSSL without NPN/ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 997
diff changeset
30
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 $t->write_file_expand('nginx.conf', <<'EOF');
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 %%TEST_GLOBALS%%
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 daemon off;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 events {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 http {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 %%TEST_GLOBALS_HTTP%%
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 server {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 listen 127.0.0.1:8080 http2 ssl;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 server_name localhost;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 ssl_certificate_key localhost.key;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 ssl_certificate localhost.crt;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
1654
341506267e16 Tests: HTTP/2 tests speedup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1488
diff changeset
50 lingering_close off;
341506267e16 Tests: HTTP/2 tests speedup.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1488
diff changeset
51
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 location / { }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 EOF
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57
1740
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
58 eval { require IO::Socket::SSL; die if $IO::Socket::SSL::VERSION < 1.56; };
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
59 plan(skip_all => 'IO::Socket::SSL version >= 1.56 required') if $@;
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
60
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
61 eval { IO::Socket::SSL->can_alpn() or die; };
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
62 plan(skip_all => 'IO::Socket::SSL with OpenSSL ALPN support required') if $@;
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
63
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
64 eval { exists &Net::SSLeay::P_alpn_selected or die; };
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
65 plan(skip_all => 'Net::SSLeay with OpenSSL ALPN support required') if $@;
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
66
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 $t->write_file('openssl.conf', <<EOF);
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 [ req ]
1488
dbce8fb5f5f8 Tests: align with OpenSSL security level 2.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1220
diff changeset
69 default_bits = 2048
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 encrypt_key = no
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 distinguished_name = req_distinguished_name
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 [ req_distinguished_name ]
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 EOF
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 my $d = $t->testdir();
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 foreach my $name ('localhost') {
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 system('openssl req -x509 -new '
1220
0af58b78df35 Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
79 . "-config $d/openssl.conf -subj /CN=$name/ "
0af58b78df35 Tests: removed single quotes from system() calls.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1116
diff changeset
80 . "-out $d/$name.crt -keyout $d/$name.key "
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 . ">>$d/openssl.out 2>&1") == 0
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 or die "Can't create certificate for $name: $!\n";
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
1740
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
85 $t->write_file('index.html', '');
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 $t->write_file('tbig.html',
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 join('', map { sprintf "XX%06dXX", $_ } (1 .. 500000)));
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 open OLDERR, ">&", \*STDERR; close STDERR;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 $t->run();
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 open STDERR, ">&", \*OLDERR;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92
1740
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
93 plan(skip_all => 'no ALPN negotiation') unless defined getconn();
1741
3408029c09f5 Tests: added HTTP/2 test with rejected ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1740
diff changeset
94 $t->plan(3);
1033
45c80276d691 Tests: unbreak for nginx built with OpenSSL without NPN/ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 997
diff changeset
95
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 ###############################################################################
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97
1743
2318ed01ce53 Tests: skip ALPN rejection tests with too old LibreSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1741
diff changeset
98 SKIP: {
2318ed01ce53 Tests: skip ALPN rejection tests with too old LibreSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1741
diff changeset
99 $t->{_configure_args} =~ /LibreSSL ([\d\.]+)/;
2318ed01ce53 Tests: skip ALPN rejection tests with too old LibreSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1741
diff changeset
100 skip 'LibreSSL too old', 1 if defined $1 and $1 lt '3.4.0';
1744
38bd7e75fe69 Tests: skip ALPN rejection tests with OpenSSL < 1.1.0.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1743
diff changeset
101 $t->{_configure_args} =~ /OpenSSL ([\d\.]+)/;
38bd7e75fe69 Tests: skip ALPN rejection tests with OpenSSL < 1.1.0.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1743
diff changeset
102 skip 'OpenSSL too old', 1 if defined $1 and $1 lt '1.1.0';
1743
2318ed01ce53 Tests: skip ALPN rejection tests with too old LibreSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1741
diff changeset
103
1741
3408029c09f5 Tests: added HTTP/2 test with rejected ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1740
diff changeset
104 TODO: {
3408029c09f5 Tests: added HTTP/2 test with rejected ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1740
diff changeset
105 local $TODO = 'not yet' unless $t->has_version('1.21.4');
3408029c09f5 Tests: added HTTP/2 test with rejected ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1740
diff changeset
106
3408029c09f5 Tests: added HTTP/2 test with rejected ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1740
diff changeset
107 ok(!get_ssl_socket(['unknown']), 'alpn rejected');
3408029c09f5 Tests: added HTTP/2 test with rejected ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1740
diff changeset
108
3408029c09f5 Tests: added HTTP/2 test with rejected ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1740
diff changeset
109 }
3408029c09f5 Tests: added HTTP/2 test with rejected ALPN.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1740
diff changeset
110
1743
2318ed01ce53 Tests: skip ALPN rejection tests with too old LibreSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1741
diff changeset
111 }
2318ed01ce53 Tests: skip ALPN rejection tests with too old LibreSSL.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1741
diff changeset
112
1740
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
113 like(http_get('/', socket => get_ssl_socket(['http/1.1'])),
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
114 qr/200 OK/, 'alpn to HTTP/1.1 fallback');
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
115
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
116 my $s = getconn(['http/1.1', 'h2']);
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
117 my $sid = $s->new_stream();
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
118 my $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
119 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
120 is($frame->{headers}->{':status'}, 200, 'alpn to HTTP/2');
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
121
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
122 # client cancels last stream after HEADERS has been created,
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 # while some unsent data was left in the SSL buffer
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 # HEADERS frame may stuck in SSL buffer and won't be sent producing alert
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125
1788
78fe648d54a7 Tests: avoid send timeout in h2_ssl.t test with canceled streams.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1744
diff changeset
126 $s = getconn(['http/1.1', 'h2']);
78fe648d54a7 Tests: avoid send timeout in h2_ssl.t test with canceled streams.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1744
diff changeset
127 $s->{socket}->setsockopt(SOL_SOCKET, SO_RCVBUF, 1024*1024) or die $!;
1740
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
128 $sid = $s->new_stream({ path => '/tbig.html' });
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 select undef, undef, undef, 0.2;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 $s->h2_rst($sid, 8);
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 $sid = $s->new_stream({ path => '/tbig.html' });
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 select undef, undef, undef, 0.2;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 $s->h2_rst($sid, 8);
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 $t->stop();
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 ###############################################################################
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 sub getconn {
1740
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
143 my ($alpn) = @_;
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
144 $alpn = ['h2'] if !defined $alpn;
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
145
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
146 my $sock = get_ssl_socket($alpn);
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
147 my $s = Test::Nginx::HTTP2->new(undef, socket => $sock)
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
148 if $sock->alpn_selected();
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
149 }
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
150
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
151 sub get_ssl_socket {
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
152 my ($alpn) = @_;
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 my $s;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 eval {
1740
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
156 local $SIG{ALRM} = sub { die "timeout\n" };
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
157 local $SIG{PIPE} = sub { die "sigpipe\n" };
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
158 alarm(8);
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
159 $s = IO::Socket::SSL->new(
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
160 Proto => 'tcp',
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
161 PeerAddr => '127.0.0.1',
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
162 PeerPort => port(8080),
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
163 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
164 SSL_alpn_protocols => $alpn,
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
165 SSL_error_trap => sub { die $_[1] }
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
166 );
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
167 alarm(0);
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 };
1740
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
169 alarm(0);
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170
1740
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
171 if ($@) {
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
172 log_in("died: $@");
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
173 return undef;
f7e667a4898d Tests: added HTTP/2 test for ALPN fallback to HTTP/1.1.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1654
diff changeset
174 }
986
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 return $s;
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 }
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178
99f93be57416 Tests: various HTTP/2 tests with canceled stream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 ###############################################################################