@@ -70,8 +70,12 @@ http {
70
70
js_content test.chain;
71
71
}
72
72
73
- location /chunked {
74
- js_content test.chunked;
73
+ location /chunked_ok {
74
+ js_content test.chunked_ok;
75
+ }
76
+
77
+ location /chunked_fail {
78
+ js_content test.chunked_fail;
75
79
}
76
80
77
81
location /header {
@@ -222,30 +226,48 @@ $t->write_file('test.js', <<EOF);
222
226
next();
223
227
}
224
228
225
- function chunked (r) {
229
+ function chunked_ok (r) {
226
230
var results = [];
227
231
var tests = [
228
- ['http://127.0.0.1:$p2 /big', {max_response_body_size:128000}],
229
232
['http://127.0.0.1:$p2 /big/ok', {max_response_body_size:128000}],
230
- ['http://127.0.0.1:$p2 /chunked'],
231
233
['http://127.0.0.1:$p2 /chunked/ok'],
232
- ['http://127.0.0.1:$p2 /chunked/big', {max_response_body_size:128}],
233
234
['http://127.0.0.1:$p2 /chunked/big'],
234
235
];
235
236
236
237
function collect(v) {
237
238
results.push(v);
238
239
239
240
if (results.length == tests.length) {
240
- results.sort();
241
- r.return(200, JSON.stringify(results));
241
+ r.return(200);
242
242
}
243
243
}
244
244
245
245
tests.forEach(args => {
246
246
ngx.fetch.apply(r, args)
247
247
.then(reply => reply.text())
248
248
.then(body => collect(body.length))
249
+ })
250
+ }
251
+
252
+ function chunked_fail(r) {
253
+ var results = [];
254
+ var tests = [
255
+ ['http://127.0.0.1:$p2 /big', {max_response_body_size:128000}],
256
+ ['http://127.0.0.1:$p2 /chunked'],
257
+ ['http://127.0.0.1:$p2 /chunked/big', {max_response_body_size:128}],
258
+ ];
259
+
260
+ function collect(v) {
261
+ results.push(v);
262
+
263
+ if (results.length == tests.length) {
264
+ r.return(200);
265
+ }
266
+ }
267
+
268
+ tests.forEach(args => {
269
+ ngx.fetch.apply(r, args)
270
+ .then(reply => reply.text())
249
271
.catch(e => collect(e.message))
250
272
})
251
273
}
@@ -358,10 +380,11 @@ $t->write_file('test.js', <<EOF);
358
380
}
359
381
360
382
export default {njs: test_njs, body, broken, broken_response, body_special,
361
- chain, chunked, header, header_iter, multi, loc, property};
383
+ chain, chunked_ok, chunked_fail, header, header_iter,
384
+ multi, loc, property};
362
385
EOF
363
386
364
- $t -> try_run(' no njs.fetch' )-> plan(33 );
387
+ $t -> try_run(' no njs.fetch' )-> plan(34 );
365
388
366
389
$t -> run_daemon(\&http_daemon, port(8082));
367
390
$t -> waitforsocket(' 127.0.0.1:' . port(8082));
@@ -418,22 +441,10 @@ is(get_json('/multi'),
418
441
' {"b":"POST::OK","c":401,"u":"http://127.0.0.1:' .$p0 .' /loc"}]' ,
419
442
' fetch multi' );
420
443
like(http_get(' /multi?throw=1' ), qr / 500/ s , ' fetch destructor' );
421
- is(get_json(' /broken' ),
422
- ' [' .
423
- ' "connect failed",' .
424
- ' "failed to convert url arg",' .
425
- ' "invalid url"]' , ' fetch broken' );
426
- is(get_json(' /broken_response' ),
427
- ' ["invalid fetch content length",' .
428
- ' "invalid fetch header",' .
429
- ' "invalid fetch status line",' .
430
- ' "prematurely closed connection",' .
431
- ' "prematurely closed connection"]' , ' fetch broken response' );
432
- is(get_json(' /chunked' ),
433
- ' [10,100010,25500,' .
434
- ' "invalid fetch chunked response",' .
435
- ' "prematurely closed connection",' .
436
- ' "very large fetch chunked response"]' , ' fetch chunked' );
444
+ like(http_get(' /broken' ), qr / 200/ s , ' fetch broken' );
445
+ like(http_get(' /broken_response' ), qr / 200/ s , ' fetch broken response' );
446
+ like(http_get(' /chunked_ok' ), qr / 200/ s , ' fetch chunked ok' );
447
+ like(http_get(' /chunked_fail' ), qr / 200/ s , ' fetch chunked fail' );
437
448
like(http_get(' /chain' ), qr / 200 OK.*SUCCESS$ / s , ' fetch chain' );
438
449
439
450
TODO: {
0 commit comments