Debian Codegraph @

t/06_upgrade.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4 use Protocol::HTTP2::Constants qw(const_name :endpoints :states);
5
6 BEGIN {
7 use_ok('Protocol::HTTP2::Connection');
8 }
9
10 subtest 'decode_upgrade_response' => sub {
11
12 my $con = Protocol::HTTP2::Connection->new(CLIENT);
13
14 my $buf = join "\x0d\x0a",
15 "\x00HTTP/1.1 101 Switching Protocols",
16 "Connection: Upgrade",
17 "SomeHeader: bla bla",
18 "Upgrade: h2c", "",
19 "here is some binary data";
20 is $con->decode_upgrade_response( \$buf, 1 ), 92, "correct pos";
21
22 $buf =~ s/101/200/;
23 is $con->decode_upgrade_response( \$buf, 1 ), undef, "no switch";
24 $buf =~ s/200/101/;
25
26 $buf =~ s/h2c/xyz/;
27 is $con->decode_upgrade_response( \$buf, 1 ), undef,
28 "wrong Upgrade protocol";
29 $buf =~ s/xyz/h2c/;
30
31 is $con->decode_upgrade_response( \substr( $buf, 0, 80 ), 1 ), 0,
32 "wait another portion of data\n";
33 };
34
35 subtest 'decode_upgrade_request' => sub {
36
37 my $con = Protocol::HTTP2::Connection->new(SERVER);
38
39 my $buf = join "\x0d\x0a",
40 "\x00GET /default.htm HTTP/1.1",
41 "Host: server.example.com",
42 "Connection: Upgrade, HTTP2-Settings",
43 "Upgrade: h2c",
44 "HTTP2-Settings: AAAABAAAAAAA",
45 "User-Agent: perl-Protocol-HTTP2/0.10",
46 "", "";
47
48 is $con->decode_upgrade_request( \$buf, 1 ), length($buf) - 1,
49 "correct pos";
50
51 };
52
53 done_testing;