| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
use lib 't/lib'; |
| 5 |
use PH2Test; |
| 6 |
use Protocol::HTTP2::Constants qw(const_name :frame_types :endpoints :states |
| 7 |
:flags); |
| 8 |
use Protocol::HTTP2::Connection; |
| 9 |
use Protocol::HTTP2::Client; |
| 10 |
use Protocol::HTTP2::Server; |
| 11 |
|
| 12 |
subtest 'ping' => sub { |
| 13 |
|
| 14 |
my $client = Protocol::HTTP2::Client->new; |
| 15 |
$client->request( |
| 16 |
':authority' => 'localhost', |
| 17 |
':method' => 'GET', |
| 18 |
':path' => '/', |
| 19 |
':scheme' => 'https', |
| 20 |
); |
| 21 |
|
| 22 |
my $server = Protocol::HTTP2::Server->new; |
| 23 |
|
| 24 |
while ( my $frame = $client->next_frame ) { |
| 25 |
$server->feed($frame); |
| 26 |
while ( $frame = $server->next_frame ) { |
| 27 |
$client->feed($frame); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
$client->ping("HELLOSRV"); |
| 32 |
my $ping = $client->next_frame; |
| 33 |
ok binary_eq( $ping, hstr("0000 0806 0000 0000 0048 454c 4c4f 5352 56") ), |
| 34 |
"ping"; |
| 35 |
$server->feed($ping); |
| 36 |
ok binary_eq( $ping = $server->next_frame, |
| 37 |
hstr("0000 0806 0100 0000 0048 454c 4c4f 5352 56") ), |
| 38 |
"ping ack"; |
| 39 |
is $server->next_frame, undef; |
| 40 |
$client->feed($ping); |
| 41 |
is $client->next_frame, undef; |
| 42 |
}; |
| 43 |
|
| 44 |
subtest 'dont mess with continuation' => sub { |
| 45 |
my $con = Protocol::HTTP2::Connection->new(CLIENT); |
| 46 |
$con->preface(1); |
| 47 |
|
| 48 |
$con->new_stream(1); |
| 49 |
my @hdrs = ( HEADERS, 0, 1, { hblock => \"\x82" } ); |
| 50 |
my @cont = ( CONTINUATION, END_HEADERS, 1, \"\x85" ); |
| 51 |
my @data = ( DATA, 0, 1, \"DATA" ); |
| 52 |
|
| 53 |
$con->enqueue( @hdrs, @cont, @data ); |
| 54 |
|
| 55 |
ok binary_eq( $con->dequeue, $con->frame_encode(@hdrs) ), "1-HEADER"; |
| 56 |
|
| 57 |
my @ping = ( PING, 0, 0, \"HELLOSRV" ); |
| 58 |
$con->enqueue_first(@ping); |
| 59 |
|
| 60 |
ok binary_eq( $con->dequeue, $con->frame_encode(@cont) ), "2-CONTINUATION"; |
| 61 |
ok binary_eq( $con->dequeue, $con->frame_encode(@ping) ), "3-PING"; |
| 62 |
ok binary_eq( $con->dequeue, $con->frame_encode(@data) ), "4-DATA"; |
| 63 |
}; |
| 64 |
|
| 65 |
done_testing |