comparison h2_cache.t @ 876:a6abbfed42c0

Tests: split HTTP/2 tests, HTTP2 package introduced.
author Andrey Zelenkov <zelenkov@nginx.com>
date Wed, 23 Mar 2016 17:23:08 +0300
parents
children d1b94c1127d6
comparison
equal deleted inserted replaced
875:c380b4b7e2e4 876:a6abbfed42c0
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for HTTP/2 protocol with cache.
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
26 my $t = Test::Nginx->new()->has(qw/http http_v2 cache/)->plan(9)
27 ->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 proxy_cache_path %%TESTDIR%%/cache keys_zone=NAME:1m;
40
41 server {
42 listen 127.0.0.1:8080 http2;
43 listen 127.0.0.1:8081;
44 server_name localhost;
45
46 location /cache {
47 proxy_pass http://127.0.0.1:8081/;
48 proxy_cache NAME;
49 proxy_cache_valid 1m;
50 }
51 location /proxy_buffering_off {
52 proxy_pass http://127.0.0.1:8081/;
53 proxy_cache NAME;
54 proxy_cache_valid 1m;
55 proxy_buffering off;
56 }
57 }
58 }
59
60 EOF
61
62 $t->write_file('t.html', 'SEE-THIS');
63 $t->run();
64
65 ###############################################################################
66
67 # simple proxy cache test
68
69 my $sess = new_session();
70 my $sid = new_stream($sess, { path => '/cache/t.html' });
71 my $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
72
73 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
74 is($frame->{headers}->{':status'}, '200', 'proxy cache');
75
76 my $etag = $frame->{headers}->{'etag'};
77
78 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
79 is($frame->{length}, length 'SEE-THIS', 'proxy cache - DATA');
80 is($frame->{data}, 'SEE-THIS', 'proxy cache - DATA payload');
81
82 $t->write_file('t.html', 'NOOP');
83
84 $sid = new_stream($sess, { headers => [
85 { name => ':method', value => 'GET', mode => 0 },
86 { name => ':scheme', value => 'http', mode => 0 },
87 { name => ':path', value => '/cache/t.html' },
88 { name => ':authority', value => 'localhost', mode => 1 },
89 { name => 'if-none-match', value => $etag }]});
90 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
91
92 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
93 is($frame->{headers}->{':status'}, 304, 'proxy cache conditional');
94
95 # HEADERS could be received with fin, followed by DATA
96
97 $sess = new_session();
98 $sid = new_stream($sess, { path => '/cache/t.html?1', method => 'HEAD' });
99
100 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
101 push @$frames, $_ for @{h2_read($sess, all => [{ sid => $sid }])};
102 ok(!grep ({ $_->{type} eq "DATA" } @$frames), 'proxy cache HEAD - no body');
103
104 # proxy cache - expect no stray empty DATA frame
105
106 TODO: {
107 local $TODO = 'not yet';
108
109 $sess = new_session();
110 $sid = new_stream($sess, { path => '/cache/t.html?2' });
111
112 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
113 my @data = grep ({ $_->{type} eq "DATA" } @$frames);
114 is(@data, 1, 'proxy cache write - data frames');
115 is(join(' ', map { $_->{data} } @data), 'SEE-THIS', 'proxy cache write - data');
116 is(join(' ', map { $_->{flags} } @data), '1', 'proxy cache write - flags');
117
118 }
119
120 # HEAD on empty cache with proxy_buffering off
121
122 $sess = new_session();
123 $sid = new_stream($sess,
124 { path => '/proxy_buffering_off/t.html?1', method => 'HEAD' });
125
126 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
127 push @$frames, $_ for @{h2_read($sess, all => [{ sid => $sid }])};
128 ok(!grep ({ $_->{type} eq "DATA" } @$frames),
129 'proxy cache HEAD buffering off - no body');
130
131 ###############################################################################