Mercurial > hg > nginx-tests
annotate h2_trailers.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 11463d379570 |
children |
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 { | |
1986
11463d379570
Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1900
diff
changeset
|
40 listen 127.0.0.1:8080; |
1193 | 41 server_name localhost; |
42 | |
1986
11463d379570
Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1900
diff
changeset
|
43 http2 on; |
11463d379570
Tests: reworked HTTP/2 tests to use "http2 on".
Maxim Dounin <mdounin@mdounin.ru>
parents:
1900
diff
changeset
|
44 |
1193 | 45 location / { |
46 add_trailer X-Var $host; | |
47 } | |
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(); | |
1646
5b1fa6e32549
Tests: avoid http2_max_field_size in h2_trailers.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
111 $sid = $s->new_stream({ path => '/continuation?h=' . 'x' x 4000 }); |
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 ############################################################################### |