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