File Coverage

blib/lib/Protocol/HTTP2/Frame/Rst_stream.pm
Criterion Covered Total %
statement 23 29 79.3
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 31 41 75.6


line stmt bran cond sub pod time code
1             package Protocol::HTTP2::Frame::Rst_stream;
2 12     12   39 use strict;
  12         14  
  12         358  
3 12     12   34 use warnings;
  12         12  
  12         260  
4 12     12   38 use Protocol::HTTP2::Constants qw(const_name :flags :errors);
  12         11  
  12         1885  
5 12     12   51 use Protocol::HTTP2::Trace qw(tracer);
  12         13  
  12         2403  
6              
7             sub decode {
8 5     5 0 800 my ( $con, $buf_ref, $buf_offset, $length ) = @_;
9 5         811 my $frame_ref = $con->decode_context->{frame};
10              
11             # RST_STREAM associated with stream
12 5 50       822 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       806 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         809 my $code = unpack( 'N', substr( $$buf_ref, $buf_offset, 4 ) );
25              
26 5         807 tracer->debug( "Receive reset stream with error code "
27             . const_name( "errors", $code )
28             . "\n" );
29 5         811 $con->stream_reset( $frame_ref->{stream}, $code );
30              
31 5         1629 return $length;
32             }
33              
34             sub encode {
35 5     5 0 821 my ( $con, $flags_ref, $stream, $data ) = @_;
36 5         841 $con->stream_reset( $stream, $data );
37 5         1629 return pack 'N', $data;
38             }
39              
40             1;