Mercurial > hg > nginx-tests
annotate grpc.t @ 1698:90201294e1b6
Tests: added grpc request body test with a special last buffer.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 03 Jun 2021 14:38:58 +0300 |
parents | 5ac6efbe5552 |
children | 202d8feedad1 |
rev | line source |
---|---|
1303 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for grpc backend. | |
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 | |
1312
6f95c0ed2335
Tests: removed proxy prerequisite from grpc tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1303
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 grpc/) |
1698
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
27 ->has(qw/upstream_keepalive/)->plan(130); |
1303 | 28 |
29 $t->write_file_expand('nginx.conf', <<'EOF'); | |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
39 %%TEST_GLOBALS_HTTP%% | |
40 | |
41 upstream u { | |
42 server 127.0.0.1:8081; | |
43 keepalive 1; | |
44 } | |
45 | |
46 server { | |
47 listen 127.0.0.1:8080 http2; | |
48 server_name localhost; | |
49 | |
50 http2_body_preread_size 128k; | |
1653
259dfb223f9a
Tests: compatibility with http2_max_header/field_size removal.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1631
diff
changeset
|
51 large_client_header_buffers 4 32k; |
1303 | 52 |
53 location / { | |
54 grpc_pass grpc://127.0.0.1:8081; | |
55 | |
56 if ($arg_if) { | |
57 # nothing | |
58 } | |
59 | |
60 limit_except GET { | |
61 # nothing | |
62 } | |
63 } | |
64 | |
65 location /KeepAlive { | |
66 grpc_pass u; | |
67 } | |
68 | |
69 location /LongHeader { | |
70 grpc_pass 127.0.0.1:8081; | |
71 grpc_set_header X-LongHeader $arg_h; | |
72 } | |
73 | |
74 location /LongField { | |
75 grpc_pass 127.0.0.1:8081; | |
76 grpc_buffer_size 65k; | |
77 } | |
78 | |
79 location /SetHost { | |
80 grpc_pass 127.0.0.1:8081; | |
81 grpc_set_header Host custom; | |
82 } | |
83 | |
84 location /SetArgs { | |
85 grpc_pass 127.0.0.1:8081; | |
86 set $args $arg_c; | |
87 } | |
88 } | |
89 } | |
90 | |
91 EOF | |
92 | |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1370
diff
changeset
|
93 $t->run(); |
1303 | 94 |
95 ############################################################################### | |
96 | |
97 my $p = port(8081); | |
98 my $f = grpc(); | |
99 | |
100 my $frames = $f->{http_start}('/SayHello'); | |
101 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
102 is($frame->{flags}, 4, 'request - HEADERS flags'); | |
103 ok((my $sid = $frame->{sid}) % 2, 'request - HEADERS sid odd'); | |
104 is($frame->{headers}{':method'}, 'POST', 'request - method'); | |
105 is($frame->{headers}{':scheme'}, 'http', 'request - scheme'); | |
106 is($frame->{headers}{':path'}, '/SayHello', 'request - path'); | |
107 is($frame->{headers}{':authority'}, "127.0.0.1:$p", 'request - authority'); | |
108 is($frame->{headers}{'content-type'}, 'application/grpc', | |
109 'request - content type'); | |
110 is($frame->{headers}{te}, 'trailers', 'request - te'); | |
111 | |
112 $frames = $f->{data}('Hello'); | |
113 ($frame) = grep { $_->{type} eq "SETTINGS" } @$frames; | |
114 is($frame->{flags}, 1, 'request - SETTINGS ack'); | |
115 is($frame->{sid}, 0, 'request - SETTINGS sid'); | |
116 is($frame->{length}, 0, 'request - SETTINGS length'); | |
117 | |
118 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
119 is($frame->{data}, 'Hello', 'request - DATA'); | |
120 is($frame->{length}, 5, 'request - DATA length'); | |
121 is($frame->{flags}, 1, 'request - DATA flags'); | |
122 is($frame->{sid}, $sid, 'request - DATA sid match'); | |
123 | |
124 $frames = $f->{http_end}(); | |
125 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
126 is($frame->{flags}, 4, 'response - HEADERS flags'); | |
127 is($frame->{sid}, 1, 'response - HEADERS sid'); | |
128 is($frame->{headers}{':status'}, '200', 'response - status'); | |
129 is($frame->{headers}{'content-type'}, 'application/grpc', | |
130 'response - content type'); | |
131 ok($frame->{headers}{server}, 'response - server'); | |
132 ok($frame->{headers}{date}, 'response - date'); | |
133 ok(my $c = $frame->{headers}{'x-connection'}, 'response - connection'); | |
134 | |
135 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
136 is($frame->{data}, 'Hello world', 'response - DATA'); | |
137 is($frame->{length}, 11, 'response - DATA length'); | |
138 is($frame->{flags}, 0, 'response - DATA flags'); | |
139 is($frame->{sid}, 1, 'response - DATA sid'); | |
140 | |
141 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
142 is($frame->{flags}, 5, 'response - trailers flags'); | |
143 is($frame->{sid}, 1, 'response - trailers sid'); | |
144 is($frame->{headers}{'grpc-message'}, '', 'response - trailers message'); | |
145 is($frame->{headers}{'grpc-status'}, '0', 'response - trailers status'); | |
146 | |
147 # next request is on a new backend connection, no sid incremented | |
148 | |
149 $frames = $f->{http_start}('/SayHello'); | |
150 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
151 is($frame->{sid}, $sid, 'request 2 - HEADERS sid again'); | |
152 $f->{data}('Hello'); | |
153 $frames = $f->{http_end}(); | |
154 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
155 cmp_ok($frame->{headers}{'x-connection'}, '>', $c, 'response 2 - connection'); | |
156 | |
1698
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
157 # request body - special last buffer |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
158 |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
159 $f->{http_start}('/SayHello'); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
160 $frames = $f->{data}('Hello', body_more => 1); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
161 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
162 is($frame->{data}, 'Hello', 'request body first - DATA'); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
163 is($frame->{length}, 5, 'request body first - DATA length'); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
164 is($frame->{flags}, 0, 'request body first - DATA flags'); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
165 $frames = $f->{data}(''); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
166 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
167 is($frame->{data}, '', 'special buffer last - DATA'); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
168 is($frame->{length}, 0, 'special buffer last - DATA length'); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
169 is($frame->{flags}, 1, 'special buffer last - DATA flags'); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
170 $frames = $f->{http_end}(); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
171 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
172 is($frame->{headers}{':status'}, '200', 'special buffer last - response'); |
90201294e1b6
Tests: added grpc request body test with a special last buffer.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1693
diff
changeset
|
173 |
1303 | 174 # upstream keepalive |
175 | |
176 $frames = $f->{http_start}('/KeepAlive'); | |
177 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
178 is($frame->{sid}, $sid, 'keepalive - HEADERS sid'); | |
179 $f->{data}('Hello'); | |
180 $frames = $f->{http_end}(); | |
181 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
182 ok($c = $frame->{headers}{'x-connection'}, 'keepalive - connection'); | |
183 | |
184 $frames = $f->{http_start}('/KeepAlive', reuse => 1); | |
185 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
186 cmp_ok($frame->{sid}, '>', $sid, 'keepalive - HEADERS sid next'); | |
187 $f->{data}('Hello'); | |
188 $frames = $f->{http_end}(); | |
189 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
190 is($frame->{headers}{'x-connection'}, $c, 'keepalive - connection reuse'); | |
191 | |
1370
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
192 # upstream keepalive |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
193 # pending control frame ack after the response |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
194 |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
195 undef $f; |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
196 $f = grpc(); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
197 |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
198 $frames = $f->{http_start}('/KeepAlive'); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
199 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
200 is($frame->{sid}, $sid, 'keepalive 2 - HEADERS sid'); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
201 $f->{data}('Hello'); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
202 $f->{settings}(0, 1 => 4096); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
203 $frames = $f->{http_end}(); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
204 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
205 ok($c = $frame->{headers}{'x-connection'}, 'keepalive 2 - connection'); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
206 |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
207 $frames = $f->{http_start}('/KeepAlive', reuse => 1); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
208 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
209 ok($frame, 'upstream keepalive reused'); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
210 |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
211 cmp_ok($frame->{sid}, '>', $sid, 'keepalive 2 - HEADERS sid next'); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
212 $f->{data}('Hello'); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
213 $frames = $f->{http_end}(); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
214 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
215 is($frame->{headers}{'x-connection'}, $c, 'keepalive 2 - connection reuse'); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
216 |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
217 undef $f; |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
218 $f = grpc(); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
219 |
1303 | 220 # various header compression formats |
221 | |
222 $f->{http_start}('/SayHello'); | |
223 $f->{data}('Hello'); | |
224 $frames = $f->{http_end}(mode => 3); | |
225 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
226 is($frame->{headers}{':status'}, '200', 'without indexing'); | |
227 is($frame->{headers}{'content-type'}, 'application/grpc', | |
228 'without indexing 2'); | |
229 | |
230 $f->{http_start}('/SayHello'); | |
231 $f->{data}('Hello'); | |
232 $frames = $f->{http_end}(mode => 4); | |
233 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
234 is($frame->{headers}{':status'}, '200', 'without indexing new'); | |
235 is($frame->{headers}{'content-type'}, 'application/grpc', | |
236 'without indexing new 2'); | |
237 | |
238 $f->{http_start}('/SayHello'); | |
239 $f->{data}('Hello'); | |
240 $frames = $f->{http_end}(mode => 5); | |
241 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
242 is($frame->{headers}{':status'}, '200', 'never indexed'); | |
243 is($frame->{headers}{'content-type'}, 'application/grpc', | |
244 'never indexed 2'); | |
245 | |
246 $f->{http_start}('/SayHello'); | |
247 $f->{data}('Hello'); | |
248 $frames = $f->{http_end}(mode => 6); | |
249 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
250 is($frame->{headers}{':status'}, '200', 'never indexed new'); | |
251 is($frame->{headers}{'content-type'}, 'application/grpc', | |
252 'never indexed new 2'); | |
253 | |
254 # padding & priority | |
255 | |
256 $f->{http_start}('/SayHello'); | |
257 $f->{data}('Hello'); | |
258 $frames = $f->{http_end}(padding => 7); | |
259 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
260 is($frame->{headers}{':status'}, '200', 'padding'); | |
261 | |
262 $f->{http_start}('/SayHello'); | |
263 $f->{data}('Hello'); | |
264 $frames = $f->{http_end}(prio => 137, dep => 0x01020304); | |
265 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
266 is($frame->{headers}{':status'}, '200', 'priority'); | |
267 | |
268 $f->{http_start}('/SayHello'); | |
269 $f->{data}('Hello'); | |
270 $frames = $f->{http_end}(padding => 7, prio => 137, dep => 0x01020304); | |
271 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
272 is($frame->{headers}{':status'}, '200', 'padding priority'); | |
273 | |
274 SKIP: { | |
275 skip 'long test', 1 unless $ENV{TEST_NGINX_UNSAFE}; | |
276 | |
277 $f->{http_start}('/SaySplit'); | |
278 $f->{data}('Hello'); | |
279 $frames = $f->{http_end}(padding => 7, prio => 137, dep => 0x01020304, | |
280 split => [(map{1}(1..20)), 30], split_delay => 0.1); | |
281 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
282 is($frame->{headers}{':status'}, '200', 'padding priority split'); | |
283 | |
284 } | |
285 | |
286 # grpc error, no empty data frame expected | |
287 | |
288 $f->{http_start}('/SayHello'); | |
289 $f->{data}('Hello'); | |
290 $frames = $f->{http_err}(); | |
291 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
292 is($frame->{flags}, 5, 'grpc error - HEADERS flags'); | |
293 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
294 ok(!$frame, 'grpc error - no DATA frame'); | |
295 | |
1583
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
296 # malformed response body length not equal to content-length |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
297 |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
298 $f->{http_start}('/SayHello'); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
299 $f->{data}('Hello'); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
300 $frames = $f->{http_err2}(cl => 42); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
301 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
302 ok($frame, 'response body less than content-length'); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
303 |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
304 $f->{http_start}('/SayHello'); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
305 $f->{data}('Hello'); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
306 $frames = $f->{http_err2}(cl => 8); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
307 ($frame) = grep { $_->{type} eq "RST_STREAM" } @$frames; |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
308 ok($frame, 'response body more than content-length'); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
309 |
1303 | 310 # continuation from backend, expect parts assembled |
311 | |
312 $f->{http_start}('/SayHello'); | |
313 $f->{data}('Hello'); | |
314 $frames = $f->{continuation}(); | |
315 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
316 is($frame->{flags}, 4, 'continuation - HEADERS flags'); | |
317 is($frame->{headers}{':status'}, '200', 'continuation - status'); | |
318 is($frame->{headers}{'content-type'}, 'application/grpc', | |
319 'continuation - content type'); | |
320 | |
321 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
322 is($frame->{data}, 'Hello world', 'continuation - DATA'); | |
323 is($frame->{length}, 11, 'continuation - DATA length'); | |
324 is($frame->{flags}, 0, 'continuation - DATA flags'); | |
325 | |
326 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
327 is($frame->{flags}, 5, 'continuation - trailers flags'); | |
328 is($frame->{headers}{'grpc-message'}, '', 'continuation - trailers message'); | |
329 is($frame->{headers}{'grpc-status'}, '0', 'continuation - trailers status'); | |
330 | |
331 # continuation from backend, header split | |
332 | |
333 $f->{http_start}('/SayHello'); | |
334 $f->{data}('Hello'); | |
335 $frames = $f->{http_end}(mode => 6, continuation => [map { 1 } (1 .. 42)]); | |
336 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
337 is($frame->{headers}{':status'}, '200', 'continuation - header split'); | |
338 | |
339 # continuation to backend | |
340 | |
341 $frames = $f->{http_start}('/LongHeader?h=' . ('Z' x 31337)); | |
342 @$frames = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames; | |
343 is(@$frames, 4, 'continuation - frames'); | |
344 | |
345 $frame = shift @$frames; | |
346 is($frame->{type}, 'HEADERS', 'continuation - HEADERS'); | |
347 is($frame->{length}, 16384, 'continuation - HEADERS length'); | |
348 is($frame->{flags}, 1, 'continuation - HEADERS flags'); | |
349 ok($frame->{sid}, 'continuation - HEADERS sid'); | |
350 | |
351 $frame = shift @$frames; | |
352 is($frame->{type}, 'CONTINUATION', 'continuation - CONTINUATION'); | |
353 is($frame->{length}, 16384, 'continuation - CONTINUATION length'); | |
354 is($frame->{flags}, 0, 'continuation - CONTINUATION flags'); | |
355 ok($frame->{sid}, 'continuation - CONTINUATION sid'); | |
356 | |
357 $frame = shift @$frames; | |
358 is($frame->{type}, 'CONTINUATION', 'continuation - CONTINUATION 2'); | |
359 is($frame->{length}, 16384, 'continuation - CONTINUATION 2 length'); | |
360 is($frame->{flags}, 0, 'continuation - CONTINUATION 2 flags'); | |
361 | |
362 $frame = shift @$frames; | |
363 is($frame->{type}, 'CONTINUATION', 'continuation - CONTINUATION n'); | |
364 cmp_ok($frame->{length}, '<', 16384, 'continuation - CONTINUATION n length'); | |
365 is($frame->{flags}, 4, 'continuation - CONTINUATION n flags'); | |
366 is($frame->{headers}{':path'}, '/LongHeader?h=' . 'Z' x 31337, | |
367 'continuation - path'); | |
368 is($frame->{headers}{'x-longheader'}, 'Z' x 31337, 'continuation - header'); | |
369 | |
370 $f->{http_end}(); | |
371 | |
372 # long header field | |
373 | |
374 $f->{http_start}('/LongField'); | |
375 $f->{data}('Hello'); | |
376 $frames = $f->{field_len}(2**7); | |
377 ($frame) = grep { $_->{flags} & 0x4 } @$frames; | |
378 is($frame->{headers}{'x' x 2**7}, 'y' x 2**7, 'long header field 1'); | |
379 | |
380 $f->{http_start}('/LongField'); | |
381 $f->{data}('Hello'); | |
382 $frames = $f->{field_len}(2**8); | |
383 ($frame) = grep { $_->{flags} & 0x4 } @$frames; | |
384 is($frame->{headers}{'x' x 2**8}, 'y' x 2**8, 'long header field 2'); | |
385 | |
386 $f->{http_start}('/LongField'); | |
387 $f->{data}('Hello'); | |
388 $frames = $f->{field_len}(2**15); | |
389 ($frame) = grep { $_->{flags} & 0x4 } @$frames; | |
390 is($frame->{headers}{'x' x 2**15}, 'y' x 2**15, 'long header field 3'); | |
391 | |
1676
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
392 # Intermediary Encapsulation Attacks, malformed header fields |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
393 |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
394 $f->{http_start}('/'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
395 $f->{data}('Hello'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
396 $frames = $f->{field_bad}(n => 'n:n'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
397 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
398 is($frame->{headers}{':status'}, 502, 'invalid header name colon'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
399 |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
400 $f->{http_start}('/'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
401 $f->{data}('Hello'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
402 $frames = $f->{field_bad}(n => 'NN'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
403 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
404 is($frame->{headers}{':status'}, 502, 'invalid header name uppercase'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
405 |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
406 $f->{http_start}('/'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
407 $f->{data}('Hello'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
408 $frames = $f->{field_bad}(n => "n\nn"); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
409 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
410 is($frame->{headers}{':status'}, 502, 'invalid header name ctl'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
411 |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
412 $f->{http_start}('/'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
413 $f->{data}('Hello'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
414 $frames = $f->{field_bad}(v => "v\nv"); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
415 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
416 is($frame->{headers}{':status'}, 502, 'invalid header value ctl'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
417 |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
418 # invalid HPACK index |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
419 |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
420 $f->{http_start}('/'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
421 $f->{data}('Hello'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
422 $frames = $f->{field_bad}('m' => 0); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
423 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
424 is($frame->{headers}{':status'}, 502, 'invalid index - indexed header'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
425 |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
426 $f->{http_start}('/'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
427 $f->{data}('Hello'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
428 $frames = $f->{field_bad}('m' => 1); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
429 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
430 is($frame->{headers}{':status'}, 502, 'invalid index - with indexing'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
431 |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
432 $f->{http_start}('/'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
433 $f->{data}('Hello'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
434 $frames = $f->{field_bad}('m' => 3); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
435 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
436 is($frame->{headers}{':status'}, 502, 'invalid index - without indexing'); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
437 |
1303 | 438 # flow control |
439 | |
440 $f->{http_start}('/FlowControl'); | |
441 $frames = $f->{data_len}(('Hello' x 13000) . ('x' x 550), 65535); | |
442 my $sum = eval join '+', map { $_->{type} eq "DATA" && $_->{length} } @$frames; | |
443 is($sum, 65535, 'flow control - iws length'); | |
444 | |
445 $f->{update}(10); | |
446 $f->{update_sid}(10); | |
447 | |
448 $frames = $f->{data_len}(undef, 10); | |
449 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
450 is($frame->{length}, 10, 'flow control - update length'); | |
451 is($frame->{flags}, 0, 'flow control - update flags'); | |
452 | |
453 $f->{update_sid}(10); | |
454 $f->{update}(10); | |
455 | |
456 $frames = $f->{data_len}(undef, 5); | |
457 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
458 is($frame->{length}, 5, 'flow control - rest length'); | |
459 is($frame->{flags}, 1, 'flow control - rest flags'); | |
460 | |
461 $f->{http_end}(); | |
462 | |
1318
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
463 # preserve output |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
464 |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
465 $f->{http_start}('/Preserve'); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
466 $f->{data}('Hello'); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
467 $frames = $f->{http_pres}(); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
468 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
469 is($frame->{flags}, 4, 'preserve - HEADERS'); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
470 |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
471 my @data = grep { $_->{type} eq "DATA" } @$frames; |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
472 $sum = eval join '+', map { $_->{length} } @data; |
1319
3b30e97acdcb
Tests: made grpc preserve output test pass on win32 and Solaris.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1318
diff
changeset
|
473 is($sum, 20480, 'preserve - DATA'); |
1318
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
474 |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
475 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
476 is($frame->{flags}, 5, 'preserve - trailers'); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
477 |
1303 | 478 # DATA padding |
479 | |
480 $f->{http_start}('/SayPadding'); | |
481 $f->{data}('Hello'); | |
482 $frames = $f->{http_end}(body_padding => 42); | |
483 ($frame) = grep { $_->{type} eq "DATA" } @$frames; | |
1362
6874b32dc3d2
Tests: renamed some grpc.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
484 is($frame->{data}, 'Hello world', 'DATA padding'); |
6874b32dc3d2
Tests: renamed some grpc.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
485 is($frame->{length}, 11, 'DATA padding - length'); |
6874b32dc3d2
Tests: renamed some grpc.t tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1321
diff
changeset
|
486 is($frame->{flags}, 0, 'DATA padding - flags'); |
1303 | 487 |
1664
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
488 # DATA padding with Content-Length |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
489 |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
490 $f->{http_start}('/SayPadding'); |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
491 $f->{data}('Hello'); |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
492 $frames = $f->{http_end}(body_padding => 42, cl => length('Hello world')); |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
493 ($frame) = grep { $_->{type} eq "DATA" } @$frames; |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
494 is($frame->{data}, 'Hello world', 'DATA padding cl'); |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
495 is($frame->{length}, 11, 'DATA padding cl - length'); |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
496 is($frame->{flags}, 0, 'DATA padding cl - flags'); |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
497 |
1303 | 498 # :authority inheritance |
499 | |
500 $frames = $f->{http_start}('/SayHello?if=1'); | |
501 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
502 is($frame->{headers}{':authority'}, "127.0.0.1:$p", 'authority in if'); | |
503 $f->{data}('Hello'); | |
504 $f->{http_end}(); | |
505 | |
506 # misc tests | |
507 | |
508 $frames = $f->{http_start}('/SetHost'); | |
509 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
510 ok(!$frame->{headers}{':authority'}, 'set host - authority'); | |
511 is($frame->{headers}{'host'}, 'custom', 'set host - host'); | |
512 $f->{data}('Hello'); | |
513 $f->{http_end}(); | |
514 | |
515 $frames = $f->{http_start}('/SetArgs?f'); | |
516 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
517 is($frame->{headers}{':path'}, '/SetArgs', 'set args'); | |
518 $f->{data}('Hello'); | |
519 $f->{http_end}(); | |
520 | |
521 $frames = $f->{http_start}('/SetArgs?c=1'); | |
522 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
523 is($frame->{headers}{':path'}, '/SetArgs?1', 'set args len'); | |
524 $f->{data}('Hello'); | |
525 $f->{http_end}(); | |
526 | |
527 $frames = $f->{http_start}('/SetArgs esc'); | |
528 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
529 is($frame->{headers}{':path'}, '/SetArgs%20esc', 'uri escape'); | |
530 $f->{data}('Hello'); | |
531 $f->{http_end}(); | |
532 | |
533 $frames = $f->{http_start}('/'); | |
534 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
535 is($frame->{headers}{':path'}, '/', 'root index'); | |
536 $f->{data}('Hello'); | |
537 $f->{http_end}(); | |
538 | |
539 $frames = $f->{http_start}('/', method => 'GET'); | |
540 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
541 is($frame->{headers}{':method'}, 'GET', 'method get'); | |
542 $f->{data}('Hello'); | |
543 $f->{http_end}(); | |
544 | |
545 $frames = $f->{http_start}('/', method => 'HEAD'); | |
546 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
547 is($frame->{headers}{':method'}, 'HEAD', 'method head'); | |
548 $f->{data}('Hello'); | |
549 $f->{http_end}(); | |
550 | |
1564
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
551 # receiving END_STREAM followed by WINDOW_UPDATE on incomplete request body |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
552 |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
553 $f->{http_start}('/Discard_WU'); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
554 $frames = $f->{discard}(); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
555 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
556 is($frame->{flags}, 5, 'discard WINDOW_UPDATE - trailers'); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
557 |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
558 # receiving END_STREAM followed by RST_STREAM NO_ERROR |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
559 |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
560 $f->{http_start}('/Discard_NE'); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
561 $frames = $f->{discard}(); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
562 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
563 is($frame->{flags}, 5, 'discard NO_ERROR - trailers'); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
564 |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
565 # receiving END_STREAM followed by several RST_STREAM NO_ERROR |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
566 |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
567 $f->{http_start}('/Discard_NE3'); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
568 $frames = $f->{discard}(); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
569 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
570 is($frame->{flags}, undef, 'discard NO_ERROR many - no trailers'); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
571 |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
572 # receiving END_STREAM followed by RST_STREAM CANCEL |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
573 |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
574 $f->{http_start}('/Discard_CNL'); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
575 $frames = $f->{discard}(); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
576 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
577 is($frame->{flags}, undef, 'discard CANCEL - no trailers'); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
578 |
1631
62a1667f60f8
Tests: fixed grpc.t after previous change.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1624
diff
changeset
|
579 undef $f; |
62a1667f60f8
Tests: fixed grpc.t after previous change.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1624
diff
changeset
|
580 $f = grpc(); |
62a1667f60f8
Tests: fixed grpc.t after previous change.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1624
diff
changeset
|
581 |
1624
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
582 # upstream keepalive, grpc error |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
583 # receiving END_STREAM followed by RST_STREAM NO_ERROR |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
584 |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
585 $f->{http_start}('/KeepAlive'); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
586 $f->{data}('Hello'); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
587 $frames = $f->{http_err_rst}(); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
588 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
589 ok($frame->{headers}{'grpc-status'}, 'keepalive 3 - grpc error, rst'); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
590 |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
591 $frames = $f->{http_start}('/KeepAlive', reuse => 1); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
592 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
593 ok($frame, 'keepalive 3 - connection reused'); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
594 |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
595 undef $f; |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
596 $f = grpc(); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
597 |
1303 | 598 ############################################################################### |
599 | |
600 sub grpc { | |
1318
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
601 my ($server, $client, $f, $s, $c, $sid, $csid, $uri); |
1303 | 602 my $n = 0; |
603 | |
604 $server = IO::Socket::INET->new( | |
605 Proto => 'tcp', | |
606 LocalHost => '127.0.0.1', | |
607 LocalPort => $p, | |
608 Listen => 5, | |
609 Reuse => 1 | |
610 ) | |
611 or die "Can't create listening socket: $!\n"; | |
612 | |
613 $f->{http_start} = sub { | |
614 ($uri, my %extra) = @_; | |
615 my $body_more = 1 if $uri !~ /LongHeader/; | |
616 my $meth = $extra{method} || 'POST'; | |
617 $s = Test::Nginx::HTTP2->new() if !defined $s; | |
1318
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
618 $csid = $s->new_stream({ body_more => $body_more, headers => [ |
1303 | 619 { name => ':method', value => $meth, mode => !!$meth }, |
620 { name => ':scheme', value => 'http', mode => 0 }, | |
621 { name => ':path', value => $uri, }, | |
622 { name => ':authority', value => 'localhost' }, | |
623 { name => 'content-type', value => 'application/grpc' }, | |
624 { name => 'te', value => 'trailers', mode => 2 }]}); | |
625 | |
626 if (!$extra{reuse}) { | |
1321
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
627 eval { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
628 local $SIG{ALRM} = sub { die "timeout\n" }; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
629 alarm(5); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
630 |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
631 $client = $server->accept() or return; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
632 |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
633 alarm(0); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
634 }; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
635 alarm(0); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
636 if ($@) { |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
637 log_in("died: $@"); |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
638 return undef; |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
639 } |
351b95be742b
Tests: fixed grpc tests hang in accept() on internal nginx error.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1319
diff
changeset
|
640 |
1303 | 641 log2c("(new connection $client)"); |
642 $n++; | |
643 | |
644 $client->sysread(my $buf, 24) == 24 or return; # preface | |
645 | |
646 $c = Test::Nginx::HTTP2->new(1, socket => $client, | |
647 pure => 1, preface => "") or return; | |
648 } | |
649 | |
650 my $frames = $c->read(all => [{ fin => 4 }]); | |
651 | |
652 if (!$extra{reuse}) { | |
653 $c->h2_settings(0); | |
654 $c->h2_settings(1); | |
655 } | |
656 | |
657 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
658 $sid = $frame->{sid}; | |
659 return $frames; | |
660 }; | |
661 $f->{data} = sub { | |
662 my ($body, %extra) = @_; | |
663 $s->h2_body($body, { %extra }); | |
664 return $c->read(all => [{ sid => $sid, | |
665 length => length($body) }]); | |
666 }; | |
667 $f->{data_len} = sub { | |
668 my ($body, $len) = @_; | |
669 $s->h2_body($body) if defined $body; | |
670 return $c->read(all => [{ sid => $sid, length => $len }]); | |
671 }; | |
672 $f->{update} = sub { | |
673 $c->h2_window(shift); | |
674 }; | |
675 $f->{update_sid} = sub { | |
676 $c->h2_window(shift, $sid); | |
677 }; | |
1370
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
678 $f->{settings} = sub { |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
679 $c->h2_settings(@_); |
23e407a72fe9
Tests: upstream keepalive with grpc pending frames.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1362
diff
changeset
|
680 }; |
1303 | 681 $f->{http_end} = sub { |
682 my (%extra) = @_; | |
1664
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
683 my $h = [ |
1303 | 684 { name => ':status', value => '200', |
685 mode => $extra{mode} || 0 }, | |
686 { name => 'content-type', value => 'application/grpc', | |
687 mode => $extra{mode} || 1, huff => 1 }, | |
688 { name => 'x-connection', value => $n, | |
1664
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
689 mode => 2, huff => 1 }]; |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
690 push @$h, { name => 'content-length', value => $extra{cl} } |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
691 if $extra{cl}; |
0fae67763be5
Tests: added grpc tests with DATA padding and Content-Length.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1653
diff
changeset
|
692 $c->new_stream({ body_more => 1, headers => $h, %extra }, $sid); |
1303 | 693 $c->h2_body('Hello world', { body_more => 1, |
694 body_padding => $extra{body_padding} }); | |
695 $c->new_stream({ headers => [ | |
696 { name => 'grpc-status', value => '0', | |
697 mode => 2, huff => 1 }, | |
698 { name => 'grpc-message', value => '', | |
699 mode => 2, huff => 1 }, | |
700 ]}, $sid); | |
701 | |
702 return $s->read(all => [{ fin => 1 }]); | |
703 }; | |
1318
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
704 $f->{http_pres} = sub { |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
705 my (%extra) = @_; |
1319
3b30e97acdcb
Tests: made grpc preserve output test pass on win32 and Solaris.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1318
diff
changeset
|
706 $s->h2_settings(0, 0x4 => 8192); |
1318
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
707 $c->new_stream({ body_more => 1, %extra, headers => [ |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
708 { name => ':status', value => '200', |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
709 mode => $extra{mode} || 0 }, |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
710 { name => 'content-type', value => 'application/grpc', |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
711 mode => $extra{mode} || 1, huff => 1 }, |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
712 { name => 'x-connection', value => $n, |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
713 mode => 2, huff => 1 }, |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
714 ]}, $sid); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
715 for (1 .. 20) { |
1319
3b30e97acdcb
Tests: made grpc preserve output test pass on win32 and Solaris.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1318
diff
changeset
|
716 $c->h2_body(sprintf('Hello %02d', $_) x 128, { |
1318
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
717 body_more => 1, |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
718 body_padding => $extra{body_padding} }); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
719 $c->h2_ping("PING"); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
720 } |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
721 # reopen window |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
722 $s->h2_window(2**24); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
723 $s->h2_window(2**24, $csid); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
724 $c->new_stream({ headers => [ |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
725 { name => 'grpc-status', value => '0', |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
726 mode => 2, huff => 1 }, |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
727 { name => 'grpc-message', value => '', |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
728 mode => 2, huff => 1 }, |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
729 ]}, $sid); |
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
730 |
1319
3b30e97acdcb
Tests: made grpc preserve output test pass on win32 and Solaris.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1318
diff
changeset
|
731 return $s->read(all => [{ sid => $csid, fin => 1 }]); |
1318
6de2a27af2d3
Tests: grpc preserve output tests added (ticket #1519).
Sergey Kandaurov <pluknet@nginx.com>
parents:
1312
diff
changeset
|
732 }; |
1303 | 733 $f->{http_err} = sub { |
734 $c->new_stream({ headers => [ | |
735 { name => ':status', value => '200', mode => 0 }, | |
736 { name => 'content-type', value => 'application/grpc', | |
737 mode => 1, huff => 1 }, | |
738 { name => 'grpc-status', value => '12', | |
739 mode => 2, huff => 1 }, | |
740 { name => 'grpc-message', value => 'unknown service', | |
741 mode => 2, huff => 1 }, | |
742 ]}, $sid); | |
743 | |
744 return $s->read(all => [{ fin => 1 }]); | |
745 }; | |
1624
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
746 $f->{http_err_rst} = sub { |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
747 $c->start_chain(); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
748 $c->new_stream({ headers => [ |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
749 { name => ':status', value => '200', mode => 0 }, |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
750 { name => 'content-type', value => 'application/grpc' }, |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
751 { name => 'grpc-status', value => '12', mode => 2 }, |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
752 { name => 'grpc-message', value => 'unknown service', |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
753 mode => 2 }, |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
754 ]}, $sid); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
755 $c->h2_rst($sid, 0); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
756 $c->send_chain(); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
757 |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
758 return $s->read(all => [{ fin => 1 }]); |
81fd6615358e
Tests: added test for "grpc error" followed by RST_STREAM NO_ERROR.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1623
diff
changeset
|
759 }; |
1583
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
760 $f->{http_err2} = sub { |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
761 my %extra = @_; |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
762 $c->new_stream({ body_more => 1, headers => [ |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
763 { name => ':status', value => '200', mode => 0 }, |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
764 { name => 'content-type', value => 'application/grpc', |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
765 mode => 1, huff => 1 }, |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
766 { name => 'content-length', value => $extra{cl}, |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
767 mode => 1, huff => 1 }, |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
768 ]}, $sid); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
769 $c->h2_body('Hello world', |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
770 { body_more => 1, body_split => [5] }); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
771 $c->new_stream({ headers => [ |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
772 { name => 'grpc-status', value => '0', |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
773 mode => 2, huff => 1 }, |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
774 { name => 'grpc-message', value => '', |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
775 mode => 2, huff => 1 }, |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
776 ]}, $sid); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
777 |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
778 return $s->read(all => [{ type => 'RST_STREAM' }]); |
8aede7babd9a
Tests: added grpc tests with wrong response size.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1564
diff
changeset
|
779 }; |
1303 | 780 $f->{continuation} = sub { |
781 $c->new_stream({ continuation => 1, body_more => 1, headers => [ | |
782 { name => ':status', value => '200', mode => 0 }, | |
783 ]}, $sid); | |
784 $c->h2_continue($sid, { continuation => 1, headers => [ | |
785 { name => 'content-type', value => 'application/grpc', | |
786 mode => 1, huff => 1 }, | |
787 ]}); | |
788 $c->h2_continue($sid, { headers => [ | |
789 # an empty CONTINUATION frame is legitimate | |
790 ]}); | |
791 $c->h2_body('Hello world', { body_more => 1 }); | |
792 $c->new_stream({ continuation => 1, headers => [ | |
793 { name => 'grpc-status', value => '0', | |
794 mode => 2, huff => 1 }, | |
795 ]}, $sid); | |
796 $c->h2_continue($sid, { headers => [ | |
797 { name => 'grpc-message', value => '', | |
798 mode => 2, huff => 1 }, | |
799 ]}); | |
800 | |
801 return $s->read(all => [{ fin => 1 }]); | |
802 }; | |
803 $f->{field_len} = sub { | |
804 my ($len) = @_; | |
805 $c->new_stream({ continuation => [map {2**14} (0..$len/2**13)], | |
806 body_more => 1, headers => [ | |
807 { name => ':status', value => '200', mode => 0 }, | |
808 { name => 'content-type', value => 'application/grpc', | |
809 mode => 1, huff => 1 }, | |
810 { name => 'x' x $len, value => 'y' x $len, mode => 6 }, | |
811 ]}, $sid); | |
812 $c->h2_body('Hello world', { body_more => 1 }); | |
813 $c->new_stream({ headers => [ | |
814 { name => 'grpc-status', value => '0', | |
815 mode => 2, huff => 1 }, | |
816 { name => 'grpc-message', value => '', | |
817 mode => 2, huff => 1 }, | |
818 ]}, $sid); | |
819 | |
820 return $s->read(all => [{ fin => 1 }]); | |
821 }; | |
1676
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
822 $f->{field_bad} = sub { |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
823 my (%extra) = @_; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
824 my $n = defined $extra{'n'} ? $extra{'n'} : 'n'; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
825 my $v = defined $extra{'v'} ? $extra{'v'} : 'v'; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
826 my $m = defined $extra{'m'} ? $extra{'m'} : 2; |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
827 $c->new_stream({ headers => [ |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
828 { name => ':status', value => '200' }, |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
829 { name => $n, value => $v, mode => $m }, |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
830 ]}, $sid); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
831 |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
832 return $s->read(all => [{ fin => 1 }]); |
816d6ceefe50
Tests: added grpc tests with malformed headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1664
diff
changeset
|
833 }; |
1564
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
834 $f->{discard} = sub { |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
835 my (%extra) = @_; |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
836 $c->new_stream({ body_more => 1, %extra, headers => [ |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
837 { name => ':status', value => '200', |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
838 mode => $extra{mode} || 0 }, |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
839 { name => 'content-type', value => 'application/grpc', |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
840 mode => $extra{mode} || 1, huff => 1 }, |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
841 { name => 'x-connection', value => $n, |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
842 mode => 2, huff => 1 }, |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
843 ]}, $sid); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
844 $c->h2_body('Hello world', { body_more => 1, |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
845 body_padding => $extra{body_padding} }); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
846 |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
847 # stick trailers and subsequent frames for reproducibility |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
848 |
1623
3fe652bc9dae
Tests: introduced HTTP/2 frames buffering option in HTTP2 package.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1622
diff
changeset
|
849 $c->start_chain(); |
3fe652bc9dae
Tests: introduced HTTP/2 frames buffering option in HTTP2 package.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1622
diff
changeset
|
850 $c->new_stream({ headers => [ |
3fe652bc9dae
Tests: introduced HTTP/2 frames buffering option in HTTP2 package.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1622
diff
changeset
|
851 { name => 'grpc-status', value => '0', mode => 2 } |
3fe652bc9dae
Tests: introduced HTTP/2 frames buffering option in HTTP2 package.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1622
diff
changeset
|
852 ]}, $sid); |
3fe652bc9dae
Tests: introduced HTTP/2 frames buffering option in HTTP2 package.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1622
diff
changeset
|
853 $c->h2_window(42, $sid) if $uri eq '/Discard_WU'; |
3fe652bc9dae
Tests: introduced HTTP/2 frames buffering option in HTTP2 package.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1622
diff
changeset
|
854 $c->h2_rst($sid, 0) if $uri eq '/Discard_NE'; |
3fe652bc9dae
Tests: introduced HTTP/2 frames buffering option in HTTP2 package.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1622
diff
changeset
|
855 $c->h2_rst($sid, 0), $c->h2_rst($sid, 0), $c->h2_rst($sid, 0) |
3fe652bc9dae
Tests: introduced HTTP/2 frames buffering option in HTTP2 package.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1622
diff
changeset
|
856 if $uri eq '/Discard_NE3'; |
3fe652bc9dae
Tests: introduced HTTP/2 frames buffering option in HTTP2 package.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1622
diff
changeset
|
857 $c->h2_rst($sid, 8) if $uri eq '/Discard_CNL'; |
3fe652bc9dae
Tests: introduced HTTP/2 frames buffering option in HTTP2 package.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1622
diff
changeset
|
858 $c->send_chain(); |
1564
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
859 |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
860 return $s->read(all => [{ fin => 1 }], wait => 2) |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
861 if $uri eq '/Discard_WU' || $uri eq '/Discard_NE'; |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
862 return $s->read(all => [{ type => 'RST_STREAM' }]); |
fe938b5daf80
Tests: more grpc tests with discarded request body.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1535
diff
changeset
|
863 }; |
1303 | 864 return $f; |
865 } | |
866 | |
867 sub log2i { Test::Nginx::log_core('|| <<', @_); } | |
868 sub log2o { Test::Nginx::log_core('|| >>', @_); } | |
869 sub log2c { Test::Nginx::log_core('||', @_); } | |
870 | |
871 ############################################################################### |