File: 06_upgrade.t

package info (click to toggle)
libprotocol-http2-perl 1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 448 kB
  • sloc: perl: 3,370; makefile: 7
file content (53 lines) | stat: -rw-r--r-- 1,377 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use strict;
use warnings;
use Test::More;
use Protocol::HTTP2::Constants qw(const_name :endpoints :states);

BEGIN {
    use_ok('Protocol::HTTP2::Connection');
}

subtest 'decode_upgrade_response' => sub {

    my $con = Protocol::HTTP2::Connection->new(CLIENT);

    my $buf = join "\x0d\x0a",
      "\x00HTTP/1.1 101 Switching Protocols",
      "Connection: Upgrade",
      "SomeHeader: bla bla",
      "Upgrade: h2c", "",
      "here is some binary data";
    is $con->decode_upgrade_response( \$buf, 1 ), 92, "correct pos";

    $buf =~ s/101/200/;
    is $con->decode_upgrade_response( \$buf, 1 ), undef, "no switch";
    $buf =~ s/200/101/;

    $buf =~ s/h2c/xyz/;
    is $con->decode_upgrade_response( \$buf, 1 ), undef,
      "wrong Upgrade protocol";
    $buf =~ s/xyz/h2c/;

    is $con->decode_upgrade_response( \substr( $buf, 0, 80 ), 1 ), 0,
      "wait another portion of data\n";
};

subtest 'decode_upgrade_request' => sub {

    my $con = Protocol::HTTP2::Connection->new(SERVER);

    my $buf = join "\x0d\x0a",
      "\x00GET /default.htm HTTP/1.1",
      "Host: server.example.com",
      "Connection: Upgrade, HTTP2-Settings",
      "Upgrade: h2c",
      "HTTP2-Settings: AAAABAAAAAAA",
      "User-Agent: perl-Protocol-HTTP2/0.10",
      "", "";

    is $con->decode_upgrade_request( \$buf, 1 ), length($buf) - 1,
      "correct pos";

};

done_testing;