File Coverage

blib/lib/Protocol/HTTP2/Frame/Goaway.pm
Criterion Covered Total %
statement 27 29 93.1
branch 3 6 50.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 36 43 83.7


line stmt bran cond sub pod time code
1             package Protocol::HTTP2::Frame::Goaway;
2 10     10   44 use strict;
  10         15  
  10         330  
3 10     10   67 use warnings;
  10         14  
  10         265  
4 10     10   42 use Protocol::HTTP2::Constants qw(const_name :flags :errors);
  10         15  
  10         2044  
5 10     10   59 use Protocol::HTTP2::Trace qw(tracer bin2hex);
  10         14  
  10         3343  
6              
7             sub decode {
8 5     5 0 974 my ( $con, $buf_ref, $buf_offset, $length ) = @_;
9 5         1053 my $frame_ref = $con->decode_context->{frame};
10              
11 5 50       975 if ( $frame_ref->{stream} != 0 ) {
12 0         0 $con->error(PROTOCOL_ERROR);
13 0         0 return undef;
14             }
15              
16 5         1012 my ( $last_stream_id, $error_code ) =
17             unpack( 'N2', substr( $$buf_ref, $buf_offset, 8 ) );
18              
19 5         1024 $last_stream_id &= 0x7FFF_FFFF;
20              
21 5         971 tracer->debug( "GOAWAY with error code "
22             . const_name( 'errors', $error_code )
23             . " last stream is $last_stream_id\n" );
24              
25 5 50       985 tracer->debug( "additional debug data: "
26             . bin2hex( substr( $$buf_ref, $buf_offset + 8 ) )
27             . "\n" )
28             if $length - 8 > 0;
29              
30 5         978 $con->goaway(1);
31              
32 5         2010 return $length;
33             }
34              
35             sub encode {
36 7     7 0 1018 my ( $con, $flags_ref, $stream, $data ) = @_;
37              
38 7         1265 $con->goaway(1);
39              
40 7         995 my $payload = pack( 'N2', @$data );
41 7         990 tracer->debug( "\tGOAWAY: last stream = $data->[0], error = "
42             . const_name( "errors", $data->[1] )
43             . "\n" );
44 7 50       1018 $payload .= $data->[2] if @$data > 2;
45 7         2037 return $payload;
46             }
47              
48             1;