| 1 | package Protocol::HTTP2::Frame::Headers; | ||||||||||||||||||||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use Protocol::HTTP2::Constants qw(:flags :errors :states :limits); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use Protocol::HTTP2::Trace qw(tracer); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | # 6.2 HEADERS | ||||||||||||||||||||||||||||||||
| 8 | 76 | ▶ | sub decode { | ||||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=8 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 9 | 76 | my ( $con, $buf_ref, $buf_offset, $length ) = @_; | |||||||||||||||||||||||||||||||
| 10 | 76 | my ( $pad, $offset, $weight, $exclusive, $stream_dep ) = ( 0, 0 ); | |||||||||||||||||||||||||||||||
| 11 | 76 | my $frame_ref = $con->decode_context->{frame}; | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | # Protocol errors | ||||||||||||||||||||||||||||||||
| 14 | 76 | ▶ | if ( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 15 | # HEADERS frames MUST be associated with a stream | ||||||||||||||||||||||||||||||||
| 16 | $frame_ref->{stream} == 0 | ||||||||||||||||||||||||||||||||
| 17 | ) | ||||||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||||||
| 19 | 0 | $con->error(PROTOCOL_ERROR); | |||||||||||||||||||||||||||||||
| 20 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 76 | ▶ | if ( $frame_ref->{flags} & PADDED ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 24 | 0 | $pad = unpack( 'C', substr( $$buf_ref, $buf_offset, 1 ) ); | |||||||||||||||||||||||||||||||
| 25 | 0 | $offset += 1; | |||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 76 | ▶ | if ( $frame_ref->{flags} & PRIORITY_FLAG ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 29 | 1 | ( $stream_dep, $weight ) = | |||||||||||||||||||||||||||||||
| 30 | unpack( 'NC', substr( $$buf_ref, $buf_offset + $offset, 5 ) ); | ||||||||||||||||||||||||||||||||
| 31 | 1 | $exclusive = $stream_dep >> 31; | |||||||||||||||||||||||||||||||
| 32 | 1 | $stream_dep &= 0x7FFF_FFFF; | |||||||||||||||||||||||||||||||
| 33 | 1 | $weight++; | |||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 1 | $con->stream_weight( $frame_ref->{stream}, $weight ); | |||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | unless ( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 37 | $con->stream_reprio( | ||||||||||||||||||||||||||||||||
| 38 | $frame_ref->{stream}, $exclusive, $stream_dep | ||||||||||||||||||||||||||||||||
| 39 | ) | ||||||||||||||||||||||||||||||||
| 40 | ) | ||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||
| 42 | 0 | tracer->error("Malformed HEADERS frame priority"); | |||||||||||||||||||||||||||||||
| 43 | 0 | $con->error(PROTOCOL_ERROR); | |||||||||||||||||||||||||||||||
| 44 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 1 | $offset += 5; | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | # Not enough space for header block | ||||||||||||||||||||||||||||||||
| 51 | 76 | my $hblock_size = $length - $offset - $pad; | |||||||||||||||||||||||||||||||
| 52 | 76 | ▶ | if ( $hblock_size < 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | 0 | $con->error(PROTOCOL_ERROR); | |||||||||||||||||||||||||||||||
| 54 | 0 | return undef; | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | $con->stream_header_block( $frame_ref->{stream}, | ||||||||||||||||||||||||||||||||
| 58 | 76 | substr( $$buf_ref, $buf_offset + $offset, $hblock_size ) ); | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | # Stream header block complete | ||||||||||||||||||||||||||||||||
| 61 | $con->stream_headers_done( $frame_ref->{stream} ) | ||||||||||||||||||||||||||||||||
| 62 | or return undef | ||||||||||||||||||||||||||||||||
| 63 | 76 | ▶ | if $frame_ref->{flags} & END_HEADERS; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$frame_ref->{'flags'} & 4 && ($con->stream_headers_done($frame_ref->{'stream'}) || (return undef))
$con->stream_headers_done($frame_ref->{"stream"}) or return undef
MC/DC0%0/2
$frame_ref->{'flags'} & 4 && ($con->stream_headers_done($frame_ref->{'stream'}) || (return undef))
$frame_ref->{'flags'} & 4
$con->stream_headers_done($frame_ref->{"stream"})
Truth table66%2/3
A && B
A= $frame_ref->{'flags'} & 4B= $con->stream_headers_done($frame_ref->{"stream"})
| |||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 74 | return $length; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 78 | ▶ | sub encode { | ||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=7 SCAR=20.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 69 | 78 | my ( $con, $flags_ref, $stream, $data_ref ) = @_; | |||||||||||||||||||||||||||||||
| 70 | 78 | my $res = ''; | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 78 | ▶ | if ( exists $data_ref->{padding} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 0 | $$flags_ref |= PADDED; | |||||||||||||||||||||||||||||||
| 74 | 0 | $res .= pack 'C', $data_ref->{padding}; | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 78 | ▶ | if ( exists $data_ref->{stream_dep} || exists $data_ref->{weight} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $data_ref->{"stream_dep"} or exists $data_ref->{"weight"}
MC/DC50%1/2
exists $data_ref->{"stream_dep"} or exists $data_ref->{"weight"}
exists $data_ref->{"stream_dep"}
exists $data_ref->{"weight"}
Truth table66%2/3
A or B
A= exists $data_ref->{"stream_dep"}B= exists $data_ref->{"weight"}
| |||||||||||||||||||||||||||||||||
| 78 | 1 | $$flags_ref |= PRIORITY_FLAG; | |||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | my $weight = ( $data_ref->{weight} || DEFAULT_WEIGHT ) - 1; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$data_ref->{'weight'} || 16
MC/DC0%0/1
$data_ref->{'weight'} || 16
$data_ref->{'weight'}
Truth table50%1/2
A
A= $data_ref->{'weight'}
| |||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | my $stream_dep = $data_ref->{stream_dep} || 0; | ||||||||||||||||||||||||||||||
|
Condition50%1/2
$data_ref->{'stream_dep'} || 0
MC/DC0%0/1
$data_ref->{'stream_dep'} || 0
$data_ref->{'stream_dep'}
Truth table50%1/2
A
A= $data_ref->{'stream_dep'}
| |||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | $stream_dep |= ( 1 << 31 ) if $data_ref->{exclusive}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | 1 | $res .= pack 'NC', $stream_dep, $weight; | |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 78 | return $res . ${ $data_ref->{hblock} }; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 13 | 1; | |||||||||||||||||||||||||||||||