comparison h2_trailers.t @ 1193:ae3a46305e38

Tests: add_trailer tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Mon, 19 Jun 2017 17:10:59 +0300
parents
children 39cfdf581253
comparison
equal deleted inserted replaced
1192:366d789f3cbf 1193:ae3a46305e38
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 });
112 $frames = $s->read(all => [{ sid => $sid, fin => 0x4 }]);
113 push @$frames, @{$s->read(all => [{ sid => $sid, fin => 0x4 }])};
114 @$frames = grep { $_->{type} =~ "HEADERS|CONTINUATION|DATA" } @$frames;
115
116 is(@$frames, 4, 'continuation - frames');
117
118 $frame = shift @$frames;
119 is($frame->{headers}->{':status'}, 200, 'continuation - header');
120 is($frame->{flags}, 4, 'continuation - header flags');
121
122 $frame = shift @$frames;
123 is($frame->{data}, 'SEE-THIS', 'continuation - data');
124 is($frame->{flags}, 0, 'continuation - data flags');
125
126 $frame = shift @$frames;
127 is($frame->{type}, 'HEADERS', 'continuation - trailer');
128 is($frame->{flags}, 1, 'continuation - trailer flags');
129
130 $frame = shift @$frames;
131 is($frame->{type}, 'CONTINUATION', 'continuation - trailer continuation');
132 is($frame->{flags}, 4, 'continuation - trailer continuation flags');
133
134 ###############################################################################