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 11     11   52 use strict;
  11         19  
  11         304  
3 11     11   57 use warnings;
  11         28  
  11         303  
4 11     11   57 use Protocol::HTTP2::Constants qw(const_name :flags :errors);
  11         17  
  11         2453  
5 11     11   61 use Protocol::HTTP2::Trace qw(tracer);
  11         24  
  11         3055  
6              
7             sub decode {
8 5     5 0 1359 my ( $con, $buf_ref, $buf_offset, $length ) = @_;
9 5         1389 my $frame_ref = $con->decode_context->{frame};
10              
11             # RST_STREAM associated with stream
12 5 50       1412 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       1402 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         1363 my $code = unpack( 'N', substr( $$buf_ref, $buf_offset, 4 ) );
25              
26 5         1393 tracer->debug( "Receive reset stream with error code "
27             . const_name( "errors", $code )
28             . "\n" );
29              
30 5         2743 return $length;
31             }
32              
33             sub encode {
34 5     5 0 1376 my ( $con, $flags_ref, $stream, $data ) = @_;
35 5         2754 return pack 'N', $data;
36             }
37              
38             1;