File Coverage

blib/lib/Protocol/HTTP2/Frame/Priority.pm
Criterion Covered Total %
statement 27 34 79.4
branch 3 6 50.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 36 48 75.0


line stmt bran cond sub pod time code
1             package Protocol::HTTP2::Frame::Priority;
2 12     12   41 use strict;
  12         11  
  12         260  
3 12     12   36 use warnings;
  12         9  
  12         236  
4 12     12   34 use Protocol::HTTP2::Constants qw(:flags :errors);
  12         11  
  12         1657  
5 12     12   53 use Protocol::HTTP2::Trace qw(tracer);
  12         16  
  12         2507  
6              
7             sub decode {
8 1     1 0 2 my ( $con, $buf_ref, $buf_offset, $length ) = @_;
9 1         3 my $frame_ref = $con->decode_context->{frame};
10              
11             # Priority frames MUST be associated with a stream
12 1 50       3 if ( $frame_ref->{stream} == 0 ) {
13 0         0 $con->error(PROTOCOL_ERROR);
14 0         0 return undef;
15             }
16              
17 1 50       3 if ( $length != 5 ) {
18 0         0 $con->error(FRAME_SIZE_ERROR);
19 0         0 return undef;
20             }
21              
22 1         3 my ( $stream_dep, $weight ) =
23             unpack( 'NC', substr( $$buf_ref, $buf_offset, 5 ) );
24 1         2 my $exclusive = $stream_dep >> 31;
25 1         1 $stream_dep &= 0x7FFF_FFFF;
26 1         1 $weight++;
27              
28 1         6 $con->stream_weight( $frame_ref->{stream}, $weight );
29 1 50       6 unless (
30             $con->stream_reprio( $frame_ref->{stream}, $exclusive, $stream_dep ) )
31             {
32 0         0 tracer->error("Malformed priority frame");
33 0         0 $con->error(PROTOCOL_ERROR);
34 0         0 return undef;
35             }
36              
37 1         4 return $length;
38             }
39              
40             sub encode {
41 1     1 0 1 my ( $con, $flags_ref, $stream, $data_ref ) = @_;
42 1         3 my $stream_dep = $data_ref->[0];
43 1         2 my $weight = $data_ref->[1] - 1;
44 1         6 pack( 'NC', $stream_dep, $weight );
45             }
46              
47             1;