comparison h2_server_push.t @ 1284:52873012ab26

Tests: added HTTP/2 server push tests with gzip (ticket #1478).
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 13 Feb 2018 15:25:42 +0300
parents 16f091962811
children aaf332b74bcf
comparison
equal deleted inserted replaced
1283:16f091962811 1284:52873012ab26
21 ############################################################################### 21 ###############################################################################
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 http_v2 proxy rewrite/) 26 my $t = Test::Nginx->new()->has(qw/http http_v2 proxy rewrite gzip/)
27 ->write_file_expand('nginx.conf', <<'EOF'); 27 ->write_file_expand('nginx.conf', <<'EOF');
28 28
29 %%TEST_GLOBALS%% 29 %%TEST_GLOBALS%%
30 30
31 daemon off; 31 daemon off;
107 } 107 }
108 108
109 location /push { 109 location /push {
110 return 200 PROMISED; 110 return 200 PROMISED;
111 } 111 }
112
113 location /gzip.html {
114 gzip on;
115 gzip_min_length 0;
116
117 http2_push /gzip.html;
118 return 200 PROMISED;
119 }
112 } 120 }
113 121
114 server { 122 server {
115 listen 127.0.0.1:8082 http2; 123 listen 127.0.0.1:8082 http2;
116 server_name max_pushes; 124 server_name max_pushes;
126 134
127 $t->write_file('t1', join('', map { sprintf "X%04dXXX", $_ } (1 .. 8202))); 135 $t->write_file('t1', join('', map { sprintf "X%04dXXX", $_ } (1 .. 8202)));
128 $t->write_file('t2', 'SEE-THIS'); 136 $t->write_file('t2', 'SEE-THIS');
129 $t->write_file('explf', join('', map { sprintf "X%06dXXX", $_ } (1 .. 6553))); 137 $t->write_file('explf', join('', map { sprintf "X%06dXXX", $_ } (1 .. 6553)));
130 138
131 $t->try_run('no http2_push')->plan(38); 139 $t->try_run('no http2_push')->plan(41);
132 140
133 ############################################################################### 141 ###############################################################################
134 142
135 # preload & format 143 # preload & format
136 144
377 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); 385 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]);
378 386
379 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 387 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
380 is($frame->{headers}->{':status'}, 400, 'incomplete headers'); 388 is($frame->{headers}->{':status'}, 400, 'incomplete headers');
381 389
390 # gzip tests
391
392 $s = Test::Nginx::HTTP2->new();
393 $sid = $s->new_stream({ headers => [
394 { name => ':method', value => 'GET', mode => 0 },
395 { name => ':scheme', value => 'http', mode => 0 },
396 { name => ':path', value => '/arg?push=/gzip.html' },
397 { name => ':authority', value => 'localhost', mode => 1 },
398 { name => 'accept-encoding', value => 'gzip' }]});
399 $frames = $s->read(all => [{ sid => 2, fin => 1 }]);
400
401 TODO: {
402 local $TODO = 'not yet';
403
404 ($frame) = grep { $_->{type} eq "PUSH_PROMISE" && $_->{sid} == $sid } @$frames;
405 is($frame->{headers}->{'accept-encoding'}, 'gzip', 'gzip - push promise');
406
407 ($frame) = grep { $_->{type} eq "HEADERS" && $_->{sid} == 2 } @$frames;
408 is($frame->{headers}->{'content-encoding'}, 'gzip', 'gzip - headers');
409
410 ($frame) = grep { $_->{type} eq "DATA" && $_->{sid} == 2 } @$frames;
411 gunzip_like($frame->{data}, qr/^PROMISED\Z/, 'gzip - response');
412
413 }
414
382 ############################################################################### 415 ###############################################################################
416
417 sub gunzip_like {
418 my ($in, $re, $name) = @_;
419
420 SKIP: {
421 eval { require IO::Uncompress::Gunzip; };
422 Test::More::skip(
423 "IO::Uncompress::Gunzip not installed", 1) if $@;
424
425 my $out;
426
427 IO::Uncompress::Gunzip::gunzip(\$in => \$out);
428
429 if ($in =~ $re) {
430 fail($name);
431 return;
432 }
433
434 like($out, $re, $name);
435 }
436 }
437
438 ###############################################################################