Debian Codegraph @

t/13_request_with_body.t

raw
1 use strict;
2 use warnings;
3 use Test::More;
4 use Protocol::HTTP2::Client;
5 use Protocol::HTTP2::Server;
6 use lib 't/lib';
7 use PH2Test qw(fake_connect);
8
9 subtest 'client POST' => sub {
10
11 plan tests => 6;
12
13 my $body = "DATA" x 10_000;
14 my $location = "https://www.example.com/";
15 my $on_done = sub {
16 my ( $headers, $data ) = @_;
17 my %h = (@$headers);
18 is $h{location}, $location, "correct redirect";
19 };
20 my %common = (
21 ':scheme' => 'http',
22 ':authority' => 'localhost:8000',
23 ':path' => '/',
24 headers => [],
25 on_done => $on_done,
26 );
27
28 my $server;
29 $server = Protocol::HTTP2::Server->new(
30 on_request => sub {
31 my ( $stream_id, $headers, $data ) = @_;
32 my %h = (@$headers);
33
34 if ( $h{':method'} eq 'POST' ) {
35 is $body, $data, 'received correct POST body';
36 }
37 elsif ( $h{':method'} eq 'PUT' ) {
38 is $body, $data, 'received correct PUT body';
39 }
40 elsif ( $h{':method'} eq 'OPTIONS' ) {
41 is $data, undef, 'no body for OPTIONS';
42 }
43 $server->response_stream(
44 ':status' => 302,
45 stream_id => $stream_id,
46 headers => [
47 location => $location
48 ],
49 );
50
51 },
52 );
53
54 my $client = Protocol::HTTP2::Client->new;
55 $client->request(
56 %common,
57 ':method' => 'POST',
58 data => $body,
59 )->request( %common, ':method' => 'OPTIONS', )->request(
60 %common,
61 ':method' => 'PUT',
62 data => $body,
63 );
64
65 fake_connect( $server, $client );
66 };
67
68 done_testing;