comparison h2_variables.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 4dc302d8e04f
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 variables.
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 rewrite/)->plan(4)
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 server {
40 listen 127.0.0.1:8080 http2;
41 server_name localhost;
42
43 location /h2 {
44 return 200 $http2;
45 }
46 location /sp {
47 return 200 $server_protocol;
48 }
49 location /scheme {
50 return 200 $scheme;
51 }
52 location /https {
53 return 200 $https;
54 }
55 }
56 }
57
58 EOF
59
60 $t->run();
61
62 ###############################################################################
63
64 # $http2
65
66 my $sess = new_session();
67 my $sid = new_stream($sess, { path => '/h2' });
68 my $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
69
70 my ($frame) = grep { $_->{type} eq "DATA" } @$frames;
71 is($frame->{data}, 'h2c', 'http variable - h2c');
72
73 # $server_protocol
74
75 $sess = new_session();
76 $sid = new_stream($sess, { path => '/sp' });
77 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
78
79 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
80 is($frame->{data}, 'HTTP/2.0', 'server_protocol variable');
81
82 # $scheme
83
84 $sess = new_session();
85 $sid = new_stream($sess, { path => '/scheme' });
86 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
87
88 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
89 is($frame->{data}, 'http', 'scheme variable');
90
91 # $https
92
93 $sess = new_session();
94 $sid = new_stream($sess, { path => '/https' });
95 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
96
97 ($frame) = grep { $_->{type} eq "DATA" } @$frames;
98 is($frame->{data}, '', 'https variable');
99
100 ###############################################################################