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