annotate grpc.t @ 1312:6f95c0ed2335

Tests: removed proxy prerequisite from grpc tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 29 Mar 2018 18:38:39 +0300
parents 42577a840a7d
children 6de2a27af2d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for grpc backend.
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use Test::Nginx::HTTP2;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21 ###############################################################################
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
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/)
1303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 ->has(qw/upstream_keepalive/);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 $t->write_file_expand('nginx.conf', <<'EOF');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 %%TEST_GLOBALS%%
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 daemon off;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 events {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 http {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 %%TEST_GLOBALS_HTTP%%
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 upstream u {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 server 127.0.0.1:8081;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 keepalive 1;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 server {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 listen 127.0.0.1:8080 http2;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 server_name localhost;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 http2_max_field_size 128k;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 http2_max_header_size 128k;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 http2_body_preread_size 128k;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 location / {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 grpc_pass grpc://127.0.0.1:8081;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 if ($arg_if) {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 # nothing
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 limit_except GET {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 # nothing
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 location /KeepAlive {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 grpc_pass u;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 location /LongHeader {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 grpc_pass 127.0.0.1:8081;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 grpc_set_header X-LongHeader $arg_h;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 location /LongField {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 grpc_pass 127.0.0.1:8081;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 grpc_buffer_size 65k;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 location /SetHost {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 grpc_pass 127.0.0.1:8081;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 grpc_set_header Host custom;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 location /SetArgs {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 grpc_pass 127.0.0.1:8081;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 set $args $arg_c;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 EOF
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 $t->try_run('no grpc')->plan(97);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96 ###############################################################################
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 my $p = port(8081);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 my $f = grpc();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 my $frames = $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 is($frame->{flags}, 4, 'request - HEADERS flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 ok((my $sid = $frame->{sid}) % 2, 'request - HEADERS sid odd');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 is($frame->{headers}{':method'}, 'POST', 'request - method');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 is($frame->{headers}{':scheme'}, 'http', 'request - scheme');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 is($frame->{headers}{':path'}, '/SayHello', 'request - path');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 is($frame->{headers}{':authority'}, "127.0.0.1:$p", 'request - authority');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110 'request - content type');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 is($frame->{headers}{te}, 'trailers', 'request - te');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 $frames = $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 ($frame) = grep { $_->{type} eq "SETTINGS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 is($frame->{flags}, 1, 'request - SETTINGS ack');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 is($frame->{sid}, 0, 'request - SETTINGS sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 is($frame->{length}, 0, 'request - SETTINGS length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 is($frame->{data}, 'Hello', 'request - DATA');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 is($frame->{length}, 5, 'request - DATA length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 is($frame->{flags}, 1, 'request - DATA flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 is($frame->{sid}, $sid, 'request - DATA sid match');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 is($frame->{flags}, 4, 'response - HEADERS flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 is($frame->{sid}, 1, 'response - HEADERS sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 is($frame->{headers}{':status'}, '200', 'response - status');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 'response - content type');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 ok($frame->{headers}{server}, 'response - server');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 ok($frame->{headers}{date}, 'response - date');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 ok(my $c = $frame->{headers}{'x-connection'}, 'response - connection');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 is($frame->{data}, 'Hello world', 'response - DATA');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 is($frame->{length}, 11, 'response - DATA length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 is($frame->{flags}, 0, 'response - DATA flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 is($frame->{sid}, 1, 'response - DATA sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 is($frame->{flags}, 5, 'response - trailers flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 is($frame->{sid}, 1, 'response - trailers sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 is($frame->{headers}{'grpc-message'}, '', 'response - trailers message');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 is($frame->{headers}{'grpc-status'}, '0', 'response - trailers status');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 # next request is on a new backend connection, no sid incremented
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 $frames = $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 is($frame->{sid}, $sid, 'request 2 - HEADERS sid again');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 cmp_ok($frame->{headers}{'x-connection'}, '>', $c, 'response 2 - connection');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 # upstream keepalive
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 $frames = $f->{http_start}('/KeepAlive');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162 is($frame->{sid}, $sid, 'keepalive - HEADERS sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166 ok($c = $frame->{headers}{'x-connection'}, 'keepalive - connection');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 $frames = $f->{http_start}('/KeepAlive', reuse => 1);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170 cmp_ok($frame->{sid}, '>', $sid, 'keepalive - HEADERS sid next');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 $frames = $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 is($frame->{headers}{'x-connection'}, $c, 'keepalive - connection reuse');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 # various header compression formats
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180 $frames = $f->{http_end}(mode => 3);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182 is($frame->{headers}{':status'}, '200', 'without indexing');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184 'without indexing 2');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 $frames = $f->{http_end}(mode => 4);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 is($frame->{headers}{':status'}, '200', 'without indexing new');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192 'without indexing new 2');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 $frames = $f->{http_end}(mode => 5);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 is($frame->{headers}{':status'}, '200', 'never indexed');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200 'never indexed 2');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204 $frames = $f->{http_end}(mode => 6);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206 is($frame->{headers}{':status'}, '200', 'never indexed new');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208 'never indexed new 2');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210 # padding & priority
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
211
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
212 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214 $frames = $f->{http_end}(padding => 7);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
215 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
216 is($frame->{headers}{':status'}, '200', 'padding');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220 $frames = $f->{http_end}(prio => 137, dep => 0x01020304);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
221 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
222 is($frame->{headers}{':status'}, '200', 'priority');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
224 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
225 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226 $frames = $f->{http_end}(padding => 7, prio => 137, dep => 0x01020304);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228 is($frame->{headers}{':status'}, '200', 'padding priority');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
230 SKIP: {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 skip 'long test', 1 unless $ENV{TEST_NGINX_UNSAFE};
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
233 $f->{http_start}('/SaySplit');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
234 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235 $frames = $f->{http_end}(padding => 7, prio => 137, dep => 0x01020304,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236 split => [(map{1}(1..20)), 30], split_delay => 0.1);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
238 is($frame->{headers}{':status'}, '200', 'padding priority split');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
239
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
241
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
242 # grpc error, no empty data frame expected
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
246 $frames = $f->{http_err}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
247 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
248 is($frame->{flags}, 5, 'grpc error - HEADERS flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
249 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250 ok(!$frame, 'grpc error - no DATA frame');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252 # continuation from backend, expect parts assembled
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
253
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256 $frames = $f->{continuation}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
258 is($frame->{flags}, 4, 'continuation - HEADERS flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259 is($frame->{headers}{':status'}, '200', 'continuation - status');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
260 is($frame->{headers}{'content-type'}, 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
261 'continuation - content type');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
262
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
263 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
264 is($frame->{data}, 'Hello world', 'continuation - DATA');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
265 is($frame->{length}, 11, 'continuation - DATA length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
266 is($frame->{flags}, 0, 'continuation - DATA flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
267
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
268 (undef, $frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
269 is($frame->{flags}, 5, 'continuation - trailers flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
270 is($frame->{headers}{'grpc-message'}, '', 'continuation - trailers message');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
271 is($frame->{headers}{'grpc-status'}, '0', 'continuation - trailers status');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
272
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
273 # continuation from backend, header split
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
274
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
275 $f->{http_start}('/SayHello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
276 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
277 $frames = $f->{http_end}(mode => 6, continuation => [map { 1 } (1 .. 42)]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
278 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
279 is($frame->{headers}{':status'}, '200', 'continuation - header split');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
280
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
281 # continuation to backend
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
282
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
283 $frames = $f->{http_start}('/LongHeader?h=' . ('Z' x 31337));
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
284 @$frames = grep { $_->{type} =~ "HEADERS|CONTINUATION" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
285 is(@$frames, 4, 'continuation - frames');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
286
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
287 $frame = shift @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
288 is($frame->{type}, 'HEADERS', 'continuation - HEADERS');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
289 is($frame->{length}, 16384, 'continuation - HEADERS length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
290 is($frame->{flags}, 1, 'continuation - HEADERS flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
291 ok($frame->{sid}, 'continuation - HEADERS sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
292
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
293 $frame = shift @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
294 is($frame->{type}, 'CONTINUATION', 'continuation - CONTINUATION');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
295 is($frame->{length}, 16384, 'continuation - CONTINUATION length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
296 is($frame->{flags}, 0, 'continuation - CONTINUATION flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
297 ok($frame->{sid}, 'continuation - CONTINUATION sid');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
298
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
299 $frame = shift @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
300 is($frame->{type}, 'CONTINUATION', 'continuation - CONTINUATION 2');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
301 is($frame->{length}, 16384, 'continuation - CONTINUATION 2 length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
302 is($frame->{flags}, 0, 'continuation - CONTINUATION 2 flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
303
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
304 $frame = shift @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
305 is($frame->{type}, 'CONTINUATION', 'continuation - CONTINUATION n');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
306 cmp_ok($frame->{length}, '<', 16384, 'continuation - CONTINUATION n length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
307 is($frame->{flags}, 4, 'continuation - CONTINUATION n flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
308 is($frame->{headers}{':path'}, '/LongHeader?h=' . 'Z' x 31337,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
309 'continuation - path');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310 is($frame->{headers}{'x-longheader'}, 'Z' x 31337, 'continuation - header');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312 $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
314 # long header field
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 $f->{http_start}('/LongField');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
318 $frames = $f->{field_len}(2**7);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
319 ($frame) = grep { $_->{flags} & 0x4 } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
320 is($frame->{headers}{'x' x 2**7}, 'y' x 2**7, 'long header field 1');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
321
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
322 $f->{http_start}('/LongField');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
323 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
324 $frames = $f->{field_len}(2**8);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
325 ($frame) = grep { $_->{flags} & 0x4 } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
326 is($frame->{headers}{'x' x 2**8}, 'y' x 2**8, 'long header field 2');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
327
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328 $f->{http_start}('/LongField');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
330 $frames = $f->{field_len}(2**15);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
331 ($frame) = grep { $_->{flags} & 0x4 } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332 is($frame->{headers}{'x' x 2**15}, 'y' x 2**15, 'long header field 3');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334 # flow control
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
336 $f->{http_start}('/FlowControl');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
337 $frames = $f->{data_len}(('Hello' x 13000) . ('x' x 550), 65535);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
338 my $sum = eval join '+', map { $_->{type} eq "DATA" && $_->{length} } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
339 is($sum, 65535, 'flow control - iws length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
340
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
341 $f->{update}(10);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
342 $f->{update_sid}(10);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
343
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
344 $frames = $f->{data_len}(undef, 10);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
345 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
346 is($frame->{length}, 10, 'flow control - update length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
347 is($frame->{flags}, 0, 'flow control - update flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
348
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
349 $f->{update_sid}(10);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
350 $f->{update}(10);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
351
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
352 $frames = $f->{data_len}(undef, 5);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
353 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
354 is($frame->{length}, 5, 'flow control - rest length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
355 is($frame->{flags}, 1, 'flow control - rest flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
356
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
357 $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
358
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
359 # DATA padding
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
360
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
361 $f->{http_start}('/SayPadding');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
362 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
363 $frames = $f->{http_end}(body_padding => 42);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
364 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
365 is($frame->{data}, 'Hello world', 'response - DATA');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
366 is($frame->{length}, 11, 'response - DATA length');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
367 is($frame->{flags}, 0, 'response - DATA flags');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
368
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
369 # :authority inheritance
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
370
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
371 $frames = $f->{http_start}('/SayHello?if=1');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
372 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
373 is($frame->{headers}{':authority'}, "127.0.0.1:$p", 'authority in if');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
374 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
375 $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
376
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
377 # misc tests
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
378
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
379 $frames = $f->{http_start}('/SetHost');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
380 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
381 ok(!$frame->{headers}{':authority'}, 'set host - authority');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
382 is($frame->{headers}{'host'}, 'custom', 'set host - host');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
383 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
384 $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
385
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
386 $frames = $f->{http_start}('/SetArgs?f');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
387 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
388 is($frame->{headers}{':path'}, '/SetArgs', 'set args');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
389 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
390 $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
391
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
392 $frames = $f->{http_start}('/SetArgs?c=1');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
393 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
394 is($frame->{headers}{':path'}, '/SetArgs?1', 'set args len');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
395 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
396 $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
397
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
398 $frames = $f->{http_start}('/SetArgs esc');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
399 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
400 is($frame->{headers}{':path'}, '/SetArgs%20esc', 'uri escape');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
401 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
402 $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
403
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
404 $frames = $f->{http_start}('/');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
405 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
406 is($frame->{headers}{':path'}, '/', 'root index');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
407 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
408 $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
409
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
410 $frames = $f->{http_start}('/', method => 'GET');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
411 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
412 is($frame->{headers}{':method'}, 'GET', 'method get');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
413 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
414 $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
415
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
416 $frames = $f->{http_start}('/', method => 'HEAD');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
417 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
418 is($frame->{headers}{':method'}, 'HEAD', 'method head');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
419 $f->{data}('Hello');
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
420 $f->{http_end}();
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
421
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
422 ###############################################################################
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
423
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
424 sub grpc {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
425 my ($server, $client, $f, $s, $c, $sid, $uri);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
426 my $n = 0;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
427
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
428 $server = IO::Socket::INET->new(
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
429 Proto => 'tcp',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
430 LocalHost => '127.0.0.1',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
431 LocalPort => $p,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
432 Listen => 5,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
433 Reuse => 1
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
434 )
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
435 or die "Can't create listening socket: $!\n";
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
436
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
437 $f->{http_start} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
438 ($uri, my %extra) = @_;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
439 my $body_more = 1 if $uri !~ /LongHeader/;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
440 my $meth = $extra{method} || 'POST';
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
441 $s = Test::Nginx::HTTP2->new() if !defined $s;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
442 $s->new_stream({ body_more => $body_more, headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
443 { name => ':method', value => $meth, mode => !!$meth },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
444 { name => ':scheme', value => 'http', mode => 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
445 { name => ':path', value => $uri, },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
446 { name => ':authority', value => 'localhost' },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
447 { name => 'content-type', value => 'application/grpc' },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
448 { name => 'te', value => 'trailers', mode => 2 }]});
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
449
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
450 if (!$extra{reuse}) {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
451 $client = $server->accept() or return;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
452 log2c("(new connection $client)");
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
453 $n++;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
454
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
455 $client->sysread(my $buf, 24) == 24 or return; # preface
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
456
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
457 $c = Test::Nginx::HTTP2->new(1, socket => $client,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
458 pure => 1, preface => "") or return;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
459 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
460
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
461 my $frames = $c->read(all => [{ fin => 4 }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
462
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
463 if (!$extra{reuse}) {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
464 $c->h2_settings(0);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
465 $c->h2_settings(1);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
466 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
467
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
468 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
469 $sid = $frame->{sid};
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
470 return $frames;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
471 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
472 $f->{data} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
473 my ($body, %extra) = @_;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
474 $s->h2_body($body, { %extra });
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
475 return $c->read(all => [{ sid => $sid,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
476 length => length($body) }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
477 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
478 $f->{data_len} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
479 my ($body, $len) = @_;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
480 $s->h2_body($body) if defined $body;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
481 return $c->read(all => [{ sid => $sid, length => $len }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
482 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
483 $f->{update} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
484 $c->h2_window(shift);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
485 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
486 $f->{update_sid} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
487 $c->h2_window(shift, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
488 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
489 $f->{http_end} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
490 my (%extra) = @_;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
491 $c->new_stream({ body_more => 1, %extra, headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
492 { name => ':status', value => '200',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
493 mode => $extra{mode} || 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
494 { name => 'content-type', value => 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
495 mode => $extra{mode} || 1, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
496 { name => 'x-connection', value => $n,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
497 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
498 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
499 $c->h2_body('Hello world', { body_more => 1,
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
500 body_padding => $extra{body_padding} });
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
501 $c->new_stream({ headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
502 { name => 'grpc-status', value => '0',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
503 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
504 { name => 'grpc-message', value => '',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
505 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
506 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
507
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
508 return $s->read(all => [{ fin => 1 }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
509 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
510 $f->{http_err} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
511 $c->new_stream({ headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
512 { name => ':status', value => '200', mode => 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
513 { name => 'content-type', value => 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
514 mode => 1, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
515 { name => 'grpc-status', value => '12',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
516 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
517 { name => 'grpc-message', value => 'unknown service',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
518 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
519 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
520
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
521 return $s->read(all => [{ fin => 1 }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
522 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
523 $f->{continuation} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
524 $c->new_stream({ continuation => 1, body_more => 1, headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
525 { name => ':status', value => '200', mode => 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
526 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
527 $c->h2_continue($sid, { continuation => 1, headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
528 { name => 'content-type', value => 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
529 mode => 1, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
530 ]});
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
531 $c->h2_continue($sid, { headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
532 # an empty CONTINUATION frame is legitimate
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
533 ]});
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
534 $c->h2_body('Hello world', { body_more => 1 });
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
535 $c->new_stream({ continuation => 1, headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
536 { name => 'grpc-status', value => '0',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
537 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
538 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
539 $c->h2_continue($sid, { headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
540 { name => 'grpc-message', value => '',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
541 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
542 ]});
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
543
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
544 return $s->read(all => [{ fin => 1 }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
545 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
546 $f->{field_len} = sub {
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
547 my ($len) = @_;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
548 $c->new_stream({ continuation => [map {2**14} (0..$len/2**13)],
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
549 body_more => 1, headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
550 { name => ':status', value => '200', mode => 0 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
551 { name => 'content-type', value => 'application/grpc',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
552 mode => 1, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
553 { name => 'x' x $len, value => 'y' x $len, mode => 6 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
554 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
555 $c->h2_body('Hello world', { body_more => 1 });
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
556 $c->new_stream({ headers => [
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
557 { name => 'grpc-status', value => '0',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
558 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
559 { name => 'grpc-message', value => '',
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
560 mode => 2, huff => 1 },
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
561 ]}, $sid);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
562
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
563 return $s->read(all => [{ fin => 1 }]);
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
564 };
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
565 return $f;
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
566 }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
567
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
568 sub log2i { Test::Nginx::log_core('|| <<', @_); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
569 sub log2o { Test::Nginx::log_core('|| >>', @_); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
570 sub log2c { Test::Nginx::log_core('||', @_); }
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
571
42577a840a7d Tests: grpc module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
572 ###############################################################################