Mercurial > hg > nginx-tests
annotate h2_trailers.t @ 1606:e4e0695552ed
Tests: fixed stream_proxy_ssl_conf_command.t.
The stream_proxy_ssl_conf_command.t test used stream return module
to return the response. Since this ignores actual request, but the
perl test code used http_get(). This might result in the request being
sent after the response is returned and the connection closed by the server,
resulting in RST being generated and no response seen by the client at all.
Fix is to use "stream(...)->read()" instead of http_get(), so
no request is sent at all, eliminating possibility of RST being
generated.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 10 Nov 2020 05:03:29 +0300 |
parents | 97c8280de681 |
children | 5b1fa6e32549 |
rev | line source |
---|---|
1193 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 trailers. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 use Test::Nginx::HTTP2; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1194
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_v2/)->plan(22) |
1193 | 27 ->write_file_expand('nginx.conf', <<'EOF'); |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 server { | |
40 listen 127.0.0.1:8080 http2; | |
41 server_name localhost; | |
42 | |
43 location / { | |
44 add_trailer X-Var $host; | |
45 } | |
46 | |
47 http2_max_field_size 256k; | |
48 | |
49 location /continuation { | |
50 # many trailers to send in parts | |
51 add_trailer X-LongHeader $arg_h; | |
52 add_trailer X-LongHeader $arg_h; | |
53 add_trailer X-LongHeader $arg_h; | |
54 add_trailer X-LongHeader $arg_h; | |
55 add_trailer X-LongHeader $arg_h; | |
56 } | |
57 } | |
58 } | |
59 | |
60 EOF | |
61 | |
62 $t->write_file('index.html', 'SEE-THIS'); | |
63 $t->write_file('empty', ''); | |
64 $t->write_file('continuation', 'SEE-THIS'); | |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1194
diff
changeset
|
65 $t->run(); |
1193 | 66 |
67 ############################################################################### | |
68 | |
69 my ($s, $sid, $frames, $frame); | |
70 | |
71 $s = Test::Nginx::HTTP2->new(); | |
72 $sid = $s->new_stream({ path => '/' }); | |
73 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
74 @$frames = grep { $_->{type} =~ "HEADERS|DATA" } @$frames; | |
75 | |
76 is(@$frames, 3, 'frames'); | |
77 | |
78 $frame = shift @$frames; | |
79 is($frame->{headers}->{':status'}, 200, 'header'); | |
80 is($frame->{headers}->{'x-var'}, undef, 'header not trailer'); | |
81 is($frame->{flags}, 4, 'header flags'); | |
82 | |
83 $frame = shift @$frames; | |
84 is($frame->{data}, 'SEE-THIS', 'data'); | |
85 is($frame->{flags}, 0, 'data flags'); | |
86 | |
87 $frame = shift @$frames; | |
88 is($frame->{headers}->{'x-var'}, 'localhost', 'trailer'); | |
89 is($frame->{flags}, 5, 'trailer flags'); | |
90 | |
91 # with zero content-length | |
92 | |
93 $s = Test::Nginx::HTTP2->new(); | |
94 $sid = $s->new_stream({ path => '/empty' }); | |
95 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
96 @$frames = grep { $_->{type} =~ "HEADERS|DATA" } @$frames; | |
97 | |
98 is(@$frames, 2, 'no data - frames'); | |
99 | |
100 $frame = shift @$frames; | |
101 is($frame->{headers}->{':status'}, 200, 'no data - header'); | |
102 is($frame->{flags}, 4, 'no data - header flags'); | |
103 | |
104 $frame = shift @$frames; | |
105 is($frame->{headers}->{'x-var'}, 'localhost', 'no data - trailer'); | |
106 is($frame->{flags}, 5, 'no data - trailer flags'); | |
107 | |
108 # CONTINUATION in response trailers | |
109 | |
110 $s = Test::Nginx::HTTP2->new(); | |
111 $sid = $s->new_stream({ path => '/continuation?h=' . 'x' x 2**12 }); | |
1194
39cfdf581253
Tests: fixed CONTINUATION test in h2_trailers.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1193
diff
changeset
|
112 $frames = $s->read(all => [{ sid => $sid, type => 'CONTINUATION' }]); |
1193 | 113 @$frames = grep { $_->{type} =~ "HEADERS|CONTINUATION|DATA" } @$frames; |
114 | |
115 is(@$frames, 4, 'continuation - frames'); | |
116 | |
117 $frame = shift @$frames; | |
118 is($frame->{headers}->{':status'}, 200, 'continuation - header'); | |
119 is($frame->{flags}, 4, 'continuation - header flags'); | |
120 | |
121 $frame = shift @$frames; | |
122 is($frame->{data}, 'SEE-THIS', 'continuation - data'); | |
123 is($frame->{flags}, 0, 'continuation - data flags'); | |
124 | |
125 $frame = shift @$frames; | |
126 is($frame->{type}, 'HEADERS', 'continuation - trailer'); | |
127 is($frame->{flags}, 1, 'continuation - trailer flags'); | |
128 | |
129 $frame = shift @$frames; | |
130 is($frame->{type}, 'CONTINUATION', 'continuation - trailer continuation'); | |
131 is($frame->{flags}, 4, 'continuation - trailer continuation flags'); | |
132 | |
133 ############################################################################### |