Mercurial > hg > nginx-tests
annotate h2_trailers.t @ 1248:70192b1baf01
Tests: added exception test to stream_js.t using 'require'.
The stream js tests introduced in edf5a3c9e36a fail on njs 0.1.14. It doesn't
currently provide an easy way to check its version, whilst we are obligated to
gracefully handle such cases somehow. With such an addition of 'require', now
the tests are skipped instead on the previous versions.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 21 Nov 2017 13:16:39 +0300 |
parents | 39cfdf581253 |
children | 97c8280de681 |
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 | |
26 my $t = Test::Nginx->new()->has(qw/http http_v2/) | |
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'); | |
65 $t->try_run('no add_trailer')->plan(22); | |
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 ############################################################################### |