File Coverage

blib/lib/Protocol/HTTP2/Frame/Rst_stream.pm
Criterion Covered Total %
statement 21 27 77.7
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 29 39 74.3


line stmt bran cond sub pod time code
1             package Protocol::HTTP2::Frame::Rst_stream;
2 10     10   41 use strict;
  10         13  
  10         327  
3 10     10   41 use warnings;
  10         14  
  10         261  
4 10     10   46 use Protocol::HTTP2::Constants qw(const_name :flags :errors);
  10         10  
  10         1886  
5 10     10   52 use Protocol::HTTP2::Trace qw(tracer);
  10         24  
  10         2296  
6              
7             sub decode {
8 5     5 0 1022 my ( $con, $buf_ref, $buf_offset, $length ) = @_;
9 5         1001 my $frame_ref = $con->decode_context->{frame};
10              
11             # RST_STREAM associated with stream
12 5 50       1311 if ( $frame_ref->{stream} == 0 ) {
13 0         0 tracer->error("Received reset stream with stream id 0");
14 0         0 $con->error(PROTOCOL_ERROR);
15 0         0 return undef;
16             }
17              
18 5 50       1019 if ( $length != 4 ) {
19 0         0 tracer->error("Received reset stream with invalid length $length");
20 0         0 $con->error(FRAME_SIZE_ERROR);
21 0         0 return undef;
22             }
23              
24 5         1025 my $code = unpack( 'N', substr( $$buf_ref, $buf_offset, 4 ) );
25              
26 5         1154 tracer->debug( "Receive reset stream with error code "
27             . const_name( "errors", $code )
28             . "\n" );
29              
30 5         2106 return $length;
31             }
32              
33             sub encode {
34 5     5 0 1726 my ( $con, $flags_ref, $stream, $data ) = @_;
35 5         2754 return pack 'N', $data;
36             }
37              
38             1;