comparison grpc.t @ 1664:0fae67763be5

Tests: added grpc tests with DATA padding and Content-Length. Starting with nginx 1.19.1, padding in response DATA frames could result in "upstream sent response body larger than indicated content length" errors.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 24 Mar 2021 14:01:50 +0300
parents 259dfb223f9a
children 816d6ceefe50
comparison
equal deleted inserted replaced
1663:bf69dcabb856 1664:0fae67763be5
22 22
23 select STDERR; $| = 1; 23 select STDERR; $| = 1;
24 select STDOUT; $| = 1; 24 select STDOUT; $| = 1;
25 25
26 my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 grpc/) 26 my $t = Test::Nginx->new()->has(qw/http rewrite http_v2 grpc/)
27 ->has(qw/upstream_keepalive/)->plan(113); 27 ->has(qw/upstream_keepalive/)->plan(116);
28 28
29 $t->write_file_expand('nginx.conf', <<'EOF'); 29 $t->write_file_expand('nginx.conf', <<'EOF');
30 30
31 %%TEST_GLOBALS%% 31 %%TEST_GLOBALS%%
32 32
430 $frames = $f->{http_end}(body_padding => 42); 430 $frames = $f->{http_end}(body_padding => 42);
431 ($frame) = grep { $_->{type} eq "DATA" } @$frames; 431 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
432 is($frame->{data}, 'Hello world', 'DATA padding'); 432 is($frame->{data}, 'Hello world', 'DATA padding');
433 is($frame->{length}, 11, 'DATA padding - length'); 433 is($frame->{length}, 11, 'DATA padding - length');
434 is($frame->{flags}, 0, 'DATA padding - flags'); 434 is($frame->{flags}, 0, 'DATA padding - flags');
435
436 # DATA padding with Content-Length
437
438 TODO: {
439 local $TODO = 'not yet'
440 if $t->has_version('1.19.1') and !$t->has_version('1.19.9');
441
442 $f->{http_start}('/SayPadding');
443 $f->{data}('Hello');
444 $frames = $f->{http_end}(body_padding => 42, cl => length('Hello world'));
445 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
446 is($frame->{data}, 'Hello world', 'DATA padding cl');
447 is($frame->{length}, 11, 'DATA padding cl - length');
448 is($frame->{flags}, 0, 'DATA padding cl - flags');
449
450 }
435 451
436 # :authority inheritance 452 # :authority inheritance
437 453
438 $frames = $f->{http_start}('/SayHello?if=1'); 454 $frames = $f->{http_start}('/SayHello?if=1');
439 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 455 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
627 $f->{settings} = sub { 643 $f->{settings} = sub {
628 $c->h2_settings(@_); 644 $c->h2_settings(@_);
629 }; 645 };
630 $f->{http_end} = sub { 646 $f->{http_end} = sub {
631 my (%extra) = @_; 647 my (%extra) = @_;
632 $c->new_stream({ body_more => 1, %extra, headers => [ 648 my $h = [
633 { name => ':status', value => '200', 649 { name => ':status', value => '200',
634 mode => $extra{mode} || 0 }, 650 mode => $extra{mode} || 0 },
635 { name => 'content-type', value => 'application/grpc', 651 { name => 'content-type', value => 'application/grpc',
636 mode => $extra{mode} || 1, huff => 1 }, 652 mode => $extra{mode} || 1, huff => 1 },
637 { name => 'x-connection', value => $n, 653 { name => 'x-connection', value => $n,
638 mode => 2, huff => 1 }, 654 mode => 2, huff => 1 }];
639 ]}, $sid); 655 push @$h, { name => 'content-length', value => $extra{cl} }
656 if $extra{cl};
657 $c->new_stream({ body_more => 1, headers => $h, %extra }, $sid);
640 $c->h2_body('Hello world', { body_more => 1, 658 $c->h2_body('Hello world', { body_more => 1,
641 body_padding => $extra{body_padding} }); 659 body_padding => $extra{body_padding} });
642 $c->new_stream({ headers => [ 660 $c->new_stream({ headers => [
643 { name => 'grpc-status', value => '0', 661 { name => 'grpc-status', value => '0',
644 mode => 2, huff => 1 }, 662 mode => 2, huff => 1 },