| 1 | ############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # finds HTTP requests + responses in tcp connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # chunked HTTP responses are supported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | package Net::Inspect::L7::HTTP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use base 'Net::Inspect::Flow'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Net::Inspect::Debug qw(:DEFAULT $DEBUG %TRACE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Hash::Util 'lock_ref_keys'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | use fields ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | 'replay', # collected and replayed in guess_protocol | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 'meta', # meta data from connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 'requests', # list of open requests, see _in0 for fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 'error', # connection has error like server sending data w/o request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 'upgrade', # true if got upgrade, CONNECT, WebSockets.. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 'connid', # connection id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 'lastreqid',# id of last request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 'offset', # offset in data stream | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 'gap_upto', # up to which offset we could manage a gap, that is where we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # only get body data (no header, chunked info..). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # [off,off] similar to offset and off is set to -1 if umlimited | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # (i.e. body ends with end of file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 'hdr_maxsz',# maximum header size for request(0), response(1) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # chunk header(2). Defaults to 64k, 16k and 2k. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | our (@EXPORT_OK,%EXPORT_TAGS); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | need_body => [qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | METHODS_WITHOUT_RQBODY METHODS_WITH_RQBODY METHODS_WITHOUT_RPBODY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | CODE_WITHOUT_RPBODY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | )] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | push @EXPORT_OK,@$_ for (values %EXPORT_TAGS); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | push @EXPORT_OK,'parse_hdrfields','parse_reqhdr','parse_rsphdr'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | METHODS_WITHOUT_RQBODY => [qw(GET HEAD DELETE CONNECT)], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | METHODS_WITH_RQBODY => [qw(POST PUT)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | METHODS_WITHOUT_RPBODY => [qw(HEAD CONNECT)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | CODE_WITHOUT_RPBODY => [100..199, 204, 205, 304], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | RQHDR_DONE => 0b00001, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | RQBDY_DONE => 0b00010, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | RQ_ERROR => 0b00100, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | RPHDR_DONE => 0b01000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | RPBDY_DONE_ON_EOF => 0b10000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # rfc2616, 2.2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # token = 1*<any CHAR except CTLs or separators> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # separators = "(" | ")" | "<" | ">" | "@" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # | "," | ";" | ":" | "\" | <"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # | "/" | "[" | "]" | "?" | "=" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # | "{" | "}" | SP | HT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | my $separator = qr{[()<>@,;:\\"/\[\]?={} \t]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | my $token = qr{[^()<>@,;:\\"/\[\]?={}\x00-\x20\x7f]+}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | my $token_value_cont = qr{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ($token): # key: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | [\040\t]*([^\r\n]*?)[\040\t]* # <space>value<space> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ((?:\r?\n[\040\t][^\r\n]*)*) # continuation lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | \r?\n # (CR)LF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | }x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # common error: "Last Modified" instead of "Last-Modified" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # squid seems to just strip invalid headers, try the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | my $xtoken = qr{[^()<>@,;:\\"/\[\]?={}\x00-\x20\x7f][^:[:^print:]]*}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | my %METHODS_WITHOUT_RQBODY = map { ($_,1) } @{METHODS_WITHOUT_RQBODY()}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | my %METHODS_WITH_RQBODY = map { ($_,1) } @{METHODS_WITH_RQBODY()}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | my %METHODS_WITHOUT_RPBODY = map { ($_,1) } @{METHODS_WITHOUT_RPBODY()}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | my %CODE_WITHOUT_RPBODY = map { ($_,1) } @{CODE_WITHOUT_RPBODY()}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | sub guess_protocol { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my ($self,$guess,$dir,$data,$eof,$time,$meta) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
guess_protocol: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ( $dir == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $rp = $self->{replay} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"replay"} ||= []
MC/DC0%0/1
$self->{"replay"} ||= []
$self->{"replay"}
Truth table0%0/2
A
A= $self->{"replay"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | push @$rp,[$data,$eof,$time]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $buf = join('',map { $_->[0] } @$rp); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( $buf =~m{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | \A[\r\n]* # initial junk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | [A-Z]{2,20}[\040\t]{1,3} # method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | \S+[\040\t]{1,3} # path/URI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | HTTP/1\.[01][\040\t]{0,3} # version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | \r?\n # (CR)LF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | (?:$xtoken:.*\r?\n(?:[\t\040].*\r?\n)* )* # field:..+cont | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | \r?\n # empty line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | }xi) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # looks like HTTP request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $obj = $self->new_connection($meta); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # replay as one piece | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $n = $obj->in(0,$buf,$rp->[-1][1],$rp->[-1][2]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | undef $self->{replay}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $n += -length($buf) + length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $n<=0 and die "object $obj did not consume alle replayed bytes"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | debug("consumed $n of ".length($data)." bytes"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return ($obj,$n); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ▶ | } elsif ( $buf =~m{[^\n]\r?\n\r?\n} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$buf =~ /[^\n]\r?\n\r?\n/ or length $buf > 65536
MC/DC0%0/2
$buf =~ /[^\n]\r?\n\r?\n/ or length $buf > 65536
$buf =~ /[^\n]\r?\n\r?\n/
length $buf > 65536
Truth table0%0/3
A or B
A= $buf =~ /[^\n]\r?\n\r?\n/B= length $buf > 65536
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | or length($buf)>2**16 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # does not look like a HTTP header for me | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | debug("does not look like HTTP header: $buf"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $guess->detach($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | debug("need more data to decide if HTTP"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # data from server but no request header from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # client yet - cannot be HTTP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | debug("got data from server before getting request from client -> no HTTP"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $guess->detach($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | my $connid = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub syn { 1 }; # in case it is attached to Net::Inspect::Tcp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
syn: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | sub new_connection { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 14 | ▶ | my ($self,$meta,%args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_connection: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 14 | my $obj = $self->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 14 | $obj->{meta} = $meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 14 | $obj->{requests} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 14 | $obj->{connid} = ++$connid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 14 | $obj->{lastreqid} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 14 | $obj->{offset} = [0,0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 14 | $obj->{gap_upto} = [0,0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 14 | $obj->{hdr_maxsz} = delete $args{header_maxsize}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 14 | ▶ | $obj->{hdr_maxsz}[0] ||= 2**16; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$obj->{"hdr_maxsz"}[0] ||= 65536
MC/DC0%0/1
$obj->{"hdr_maxsz"}[0] ||= 65536
$obj->{"hdr_maxsz"}[0]
Truth table50%1/2
A
A= $obj->{"hdr_maxsz"}[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 14 | ▶ | $obj->{hdr_maxsz}[1] ||= 2**14; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$obj->{"hdr_maxsz"}[1] ||= 16384
MC/DC0%0/1
$obj->{"hdr_maxsz"}[1] ||= 16384
$obj->{"hdr_maxsz"}[1]
Truth table50%1/2
A
A= $obj->{"hdr_maxsz"}[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 14 | ▶ | $obj->{hdr_maxsz}[2] ||= 2**11; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$obj->{"hdr_maxsz"}[2] ||= 2048
MC/DC0%0/1
$obj->{"hdr_maxsz"}[2] ||= 2048
$obj->{"hdr_maxsz"}[2]
Truth table50%1/2
A
A= $obj->{"hdr_maxsz"}[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 14 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | sub in { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 92 | ▶ | my ($self,$dir,$data,$eof,$time) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in: called CC=5 SCAR=19.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 92 | ▶ | $DEBUG && $self->xdebug("got %s bytes from %d, eof=%d", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
$eof // 0
MC/DC0%0/1
$eof // 0
$eof
Truth table0%0/2
A
A= $eof
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | ref($data) ? join(":",@$data): length($data), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | $dir,$eof//0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 92 | ▶ | my $bytes = $dir == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ? _in0($self,$data,$eof,$time) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | : _in1($self,$data,$eof,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | #$self->dump_state if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 92 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | sub offset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
offset: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | return @{ $self->{offset} }[wantarray ? @_:$_[0]]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | sub gap_diff { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 29 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gap_diff: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 29 | my @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 29 | for(@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 58 | my $off = $self->{gap_upto}[$_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | push @rv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | $off == -1 ? -1 : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 58 | ▶ | ($off-=$self->{offset}[$_]) > 0 ? $off : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 29 | ▶ | return wantarray ? @rv : $rv[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | sub set_gap_diff { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 2 | ▶ | my ($self,$dir,$diff) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_gap_diff: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | $self->{gap_upto}[$dir] = defined($diff) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | ▶ | ? $self->{offset}[$dir] + $diff # add to offset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | : 0; # reset gap_upto | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | sub gap_offset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 16 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gap_offset: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 16 | my @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 16 | for(@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 32 | my $off = $self->{gap_upto}[$_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | push @rv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | $off == -1 ? -1 : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 32 | ▶ | $off > $self->{offset}[$_] ? $off : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 16 | ▶ | return wantarray ? @rv : $rv[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # give requests a chance to cleanup before destroying connection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 14 | @{$self->{requests}} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # process request data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | sub _in0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 55 | ▶ | my ($self,$data,$eof,$time) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_in0: called CC=106 SCAR=67.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 55 | my $bytes = 0; # processed bytes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 55 | my $rqs = $self->{requests}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 55 | ▶ | if ( ref($data)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # process gap in request data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 7 | ▶ | croak "unknown type $data->[0]" if $data->[0] ne 'gap'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 7 | my $len = $data->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 7 | ▶ | croak 'existing error in connection' if $self->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 7 | my $rqs = $self->{requests}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | croak 'no open request' if ! @$rqs or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | ▶ | $rqs->[0]{state} & RQBDY_DONE && ! $self->{upgrade}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not @$rqs or $rqs->[0]{"state"} & 2 and not $self->{"upgrade"}
$rqs->[0]{"state"} & 2 and not $self->{"upgrade"}
MC/DC0%0/3
not @$rqs or $rqs->[0]{"state"} & 2 and not $self->{"upgrade"}
not @$rqs
$rqs->[0]{"state"} & 2
not $self->{"upgrade"}
Truth table25%1/4
not(A) or B and not(C)
A= not @$rqsB= $rqs->[0]{"state"} & 2C= not $self->{"upgrade"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 7 | ▶ | croak 'existing error in request' if $rqs->[0]{state} & RQ_ERROR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | croak "gap too large" if $self->{gap_upto}[0]>=0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 7 | ▶ | && $self->{gap_upto}[0] < $self->{offset}[0] + $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"gap_upto"}[0] >= 0 and $self->{"gap_upto"}[0] < $self->{"offset"}[0] + $len
MC/DC0%0/2
$self->{"gap_upto"}[0] >= 0 and $self->{"gap_upto"}[0] < $self->{"offset"}[0] + $len
$self->{"gap_upto"}[0] >= 0
$self->{"gap_upto"}[0] < $self->{"offset"}[0] + $len
Truth table33%1/3
A and B
A= $self->{"gap_upto"}[0] >= 0B= $self->{"gap_upto"}[0] < $self->{"offset"}[0] + $len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 7 | ▶ | if (defined $rqs->[0]{rqclen}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | $rqs->[0]{rqclen} -= $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 2 | ▶ | if ( ! $rqs->[0]{rqclen} && ! $rqs->[0]{rqchunked} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$rqs->[0]{"rqclen"} or $rqs->[0]{"rqchunked"}
MC/DC0%0/2
$rqs->[0]{"rqclen"} or $rqs->[0]{"rqchunked"}
$rqs->[0]{"rqclen"}
$rqs->[0]{"rqchunked"}
Truth table33%1/3
A or B
A= $rqs->[0]{"rqclen"}B= $rqs->[0]{"rqchunked"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | $rqs->[0]{state} |= RQBDY_DONE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 7 | $self->{offset}[0] += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 7 | my $obj = $rqs->[0]{obj}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 7 | ▶ | if ($self->{upgrade}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 5 | $self->{upgrade}(0,[ gap => $len ],$eof,$time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } elsif ($obj) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | $obj->in_request_body( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | [ gap => $len ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 2 | ▶ | $eof || ($rqs->[0]{state} & RQBDY_DONE ? 1:0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$eof || ($rqs->[0]{'state'} & 2 ? 1 : 0)
MC/DC0%0/2
$eof || ($rqs->[0]{'state'} & 2 ? 1 : 0)
$eof
($rqs->[0]{'state'} & 2 ? 1 : 0)
Truth table33%1/3
A || B
A= $eofB= ($rqs->[0]{'state'} & 2 ? 1 : 0)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | $time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 7 | return $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | READ_DATA: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 85 | ▶ | if ($self->{error}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | $DEBUG && $self->xdebug("no more data because of server side error"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 85 | ▶ | if ($self->{upgrade}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 10 | $self->{offset}[0] += length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 10 | $self->{upgrade}(0,$data,$eof,$time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 10 | return $bytes + length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 75 | ▶ | if (@$rqs and $rqs->[0]{state} & RQ_ERROR ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$rqs and $rqs->[0]{"state"} & 4
MC/DC0%0/2
@$rqs and $rqs->[0]{"state"} & 4
@$rqs
$rqs->[0]{"state"} & 4
Truth table66%2/3
A and B
A= @$rqsB= $rqs->[0]{"state"} & 4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # error reading request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | $DEBUG && $self->xdebug("no more data because of client side error"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 75 | ▶ | if ( ( ! @$rqs or $rqs->[0]{state} & RQBDY_DONE ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
!@$rqs || $rqs->[0]{"state"} & 2 and $data =~ /\A[\r\n]+/g
not @$rqs or $rqs->[0]{"state"} & 2
MC/DC0%0/3
!@$rqs || $rqs->[0]{"state"} & 2 and $data =~ /\A[\r\n]+/g
not @$rqs
$rqs->[0]{"state"} & 2
$data =~ /\A[\r\n]+/g
Truth table60%3/5
not(A) or B and C
A= not @$rqsB= $rqs->[0]{"state"} & 2C= $data =~ /\A[\r\n]+/g
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | and $data =~m{\A[\r\n]+}g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # first request or previous request body done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # new request might follow but maybe we only have trailing lines after | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # the last request: eat empty lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $n = pos($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $bytes += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $self->{offset}[0] += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | substr($data,0,$n,''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | %TRACE && $self->xtrace("eat empty lines before request header"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 75 | ▶ | if ( $data eq '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 28 | ▶ | $DEBUG && $self->xdebug("no data, eof=$eof, bytes=$bytes"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 28 | ▶ | return $bytes if ! $eof; # need more data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # handle EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # check if we got request body for last request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if ( @$rqs and not $rqs->[0]{state} & RQBDY_DONE ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$rqs and not $rqs->[0]{"state"} & 2
MC/DC0%0/2
@$rqs and not $rqs->[0]{"state"} & 2
@$rqs
not $rqs->[0]{"state"} & 2
Truth table0%0/3
A and not(B)
A= @$rqsB= not $rqs->[0]{"state"} & 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # request body not done yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | %TRACE && ($rqs->[0]{obj}||$self)->xtrace("request body not done but eof"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rqs->[0]{'obj'} || $self
MC/DC0%0/2
$rqs->[0]{'obj'} || $self
$rqs->[0]{'obj'}
$self
Truth table0%0/3
A || B
A= $rqs->[0]{'obj'}B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | ($rqs->[0]{obj}||$self)->fatal('eof but request body not done',0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$rqs->[0]{'obj'} || $self
MC/DC0%0/2
$rqs->[0]{'obj'} || $self
$rqs->[0]{'obj'}
$self
Truth table0%0/3
A || B
A= $rqs->[0]{'obj'}B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $rqs->[0]{state} |= RQ_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | return $bytes; # request body done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # create new request if no open request or last open request has the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # request body already done (pipelining) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 47 | ▶ | if ( ! @$rqs or $rqs->[0]{state} & RQBDY_DONE ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not @$rqs or $rqs->[0]{"state"} & 2
MC/DC100%2/2
not @$rqs or $rqs->[0]{"state"} & 2
not @$rqs
$rqs->[0]{"state"} & 2
Truth table100%3/3
not(A) or B
A= not @$rqsB= $rqs->[0]{"state"} & 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 17 | my $reqid = ++$self->{lastreqid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | my $obj = $self->new_request({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 17 | %{$self->{meta}}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | time => $time, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | reqid => $reqid, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 17 | my $rq = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | obj => $obj, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # bitmask what is done: rpbody|rphdr|rqerror|rqbody|rqhdr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | state => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | rqclen => undef, # open content-length request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | rpclen => undef, # open content-length response | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # chunked mode for request|response: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # false - no chunking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # 1,r[qp]clen == 0 - next will be chunk size | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # 1,r[qp]clen > 0 - inside chunk data, need *clen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # 2 - next will be chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # 3 - after last chunk, next will be chunk trailer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | rqchunked => undef, # chunked mode for request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | rpchunked => undef, # chunked mode for response | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | request => undef, # result from parse_reqhdr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 17 | ▶ | if ($DEBUG) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $rq->{reqid} = $reqid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | weaken($rq->{conn} = $self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | bless $rq, 'Net::Inspect::L7::HTTP::_DebugRequest'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $rq->xdebug("create new request"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 17 | lock_ref_keys($rq); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 17 | unshift @$rqs, $rq; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 47 | my $rq = $rqs->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 47 | my $obj = $rq->{obj}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # read request header if not done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 47 | ▶ | if ( not $rq->{state} & RQHDR_DONE ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # no request header yet, check if data contains it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # leading newlines at beginning of request are legally ignored junk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 20 | ▶ | if ( $data =~s{\A([\r\n]+)}{} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | ($obj||$self)->in_junk(0,$1,0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 20 | ▶ | $DEBUG && $rq->xdebug("need to read request header"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 20 | ▶ | if ($data =~s{\A(\A.*?\n\r?\n)}{}s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 17 | ▶ | $DEBUG && $rq->xdebug("got request header"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 17 | my $hdr = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 17 | my $n = length($hdr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 17 | $self->{offset}[0] += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 17 | $bytes += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 17 | $rq->{state} |= RQHDR_DONE; # rqhdr done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 17 | my (%hdr,@warn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 17 | my $err = parse_reqhdr($hdr,\%hdr,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 17 | ▶ | if ($err and my $sub = $obj->can('fix_reqhdr')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$err and my $sub = $obj->can("fix_reqhdr")
MC/DC0%0/2
$err and my $sub = $obj->can("fix_reqhdr")
$err
my $sub = $obj->can("fix_reqhdr")
Truth table66%2/3
A and B
A= $errB= my $sub = $obj->can("fix_reqhdr")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $hdr = $sub->($obj,$hdr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $err = parse_reqhdr($hdr,\%hdr,0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 17 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | ($obj||$self)->fatal($err,0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table33%1/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | $rq->{state} |= RQ_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 16 | my $body_done; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 16 | ▶ | if ($hdr{chunked}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 4 | $rq->{rqchunked} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } elsif ($hdr{content_length}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 3 | $rq->{rqclen} = $hdr{content_length}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 3 | $self->{gap_upto}[0]= $self->{offset}[0] + $hdr{content_length}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 9 | $body_done = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 16 | $rq->{request} = \%hdr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 16 | ▶ | %TRACE && $hdr{junk} && ($obj||$self)->xtrace( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
%Net::Inspect::L7::HTTP::TRACE and $hdr{"junk"}
$obj || $self
MC/DC0%0/2
%Net::Inspect::L7::HTTP::TRACE and $hdr{"junk"}
%Net::Inspect::L7::HTTP::TRACE
$hdr{"junk"}
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table33%1/3
A and B
A= %Net::Inspect::L7::HTTP::TRACEB= $hdr{"junk"}
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | "invalid request header data: $hdr{junk}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 16 | ▶ | $obj && $obj->in_request_header($hdr,$time,\%hdr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 16 | ▶ | if ($body_done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 9 | ▶ | $DEBUG && $rq->xdebug("request done (no body)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 9 | $rq->{state} |= RQBDY_DONE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 9 | ▶ | if ($hdr{method} eq 'CONNECT' || $hdr{upgrade}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$hdr{"method"} eq "CONNECT" or $hdr{"upgrade"}
MC/DC100%2/2
$hdr{"method"} eq "CONNECT" or $hdr{"upgrade"}
$hdr{"method"} eq "CONNECT"
$hdr{"upgrade"}
Truth table100%3/3
A or B
A= $hdr{"method"} eq "CONNECT"B= $hdr{"upgrade"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # Don't propagate an empty request body: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # with CONNECT there will be no body and with Upgrade we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # will have no body if the upgrade succeeded. If it failed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # we submit the body later. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 7 | ▶ | $obj && $obj->in_request_body('',1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } elsif ($data =~m{[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # junk data, maybe attempt to use SOCKS instead of proxy request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | ($obj||$self)->fatal( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | "junk data instead of request header '%s...'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | substr($data,0,10)),0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $rq->{state} |= RQ_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } elsif ( length($data) > $self->{hdr_maxsz}[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | ($obj||$self)->fatal('request header too big',0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $rq->{state} |= RQ_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } elsif ( $eof ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | ($obj||$self)->fatal('eof in request header',0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $rq->{state} |= RQ_ERROR; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # will be called on new data from upper flow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 3 | ▶ | $DEBUG && $rq->xdebug("need more bytes for request header"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 3 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # read request body if not done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 43 | ▶ | if ( $data ne '' and not $rq->{state} & RQBDY_DONE ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$data ne "" and not $rq->{"state"} & 2
MC/DC50%1/2
$data ne "" and not $rq->{"state"} & 2
$data ne ""
not $rq->{"state"} & 2
Truth table66%2/3
A and not(B)
A= $data ne ""B= not $rq->{"state"} & 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # request body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 27 | ▶ | if ( my $want = $rq->{rqclen} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 10 | my $l = length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 10 | ▶ | if ( $l>=$want) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # got all request body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 8 | ▶ | $DEBUG && $rq->xdebug("need $want bytes, got all"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 8 | my $body = substr($data,0,$rq->{rqclen},''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 8 | $self->{offset}[0] += $rq->{rqclen}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 8 | $bytes += $rq->{rqclen}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 8 | $rq->{rqclen} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 8 | ▶ | if ( ! $rq->{rqchunked} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | ▶ | $DEBUG && $rq->xdebug("request done (full clen)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 1 | $rq->{state} |= RQBDY_DONE; # req body done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | ▶ | $obj && $obj->in_request_body($body,1,$time) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 7 | ▶ | $obj && $obj->in_request_body($body,$eof,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 7 | $rq->{rqchunked} = 2; # get CRLF after chunk | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # only part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 2 | ▶ | $DEBUG && $rq->xdebug("need $want bytes, got only $l"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 2 | my $body = substr($data,0,$l,''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 2 | $self->{offset}[0] += $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 2 | $bytes += $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 2 | $rq->{rqclen} -= $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 2 | ▶ | $obj && $obj->in_request_body($body,0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # Chunking: rfc2616, 3.6.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # [2] must get CRLF after chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 17 | ▶ | if ( $rq->{rqchunked} == 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 7 | ▶ | $DEBUG && $rq->xdebug("want CRLF after chunk"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 7 | ▶ | if ( $data =~m{\A\r?\n}g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 7 | my $n = pos($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 7 | $self->{offset}[0] += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 7 | $bytes += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 7 | substr($data,0,$n,''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 7 | $rq->{rqchunked} = 1; # get next chunk header | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 7 | ▶ | $DEBUG && $rq->xdebug("got CRLF after chunk"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } elsif ( length($data)>=2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | ▶ | ($obj||$self)->fatal("no CRLF after chunk",0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # need more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # [1] must read chunk header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 17 | ▶ | if ( $rq->{rqchunked} == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 17 | ▶ | $DEBUG && $rq->xdebug("want chunk header"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 17 | ▶ | if ( $data =~m{\A([\da-fA-F]+)[ \t]*(?:;.*)?\r?\n}g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 11 | $rq->{rqclen} = hex($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 11 | my $chdr = substr($data,0,pos($data),''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 11 | $self->{offset}[0] += length($chdr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 11 | $bytes += length($chdr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | $self->{gap_upto}[0] = $self->{offset}[0] + $rq->{rqclen} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 11 | ▶ | if $rq->{rqclen}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 11 | ▶ | $obj->in_chunk_header(0,$chdr,$time) if $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 11 | ▶ | $DEBUG && $rq->xdebug( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | "got chunk header - want $rq->{rqclen} bytes"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 11 | ▶ | if ( ! $rq->{rqclen} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # last chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 4 | $rq->{rqchunked} = 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 4 | ▶ | $obj && $obj->in_request_body('',1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | ▶ | } elsif ( $data =~m{\n} or length($data)>8192 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$data =~ /\n/ or length $data > 8192
MC/DC0%0/2
$data =~ /\n/ or length $data > 8192
$data =~ /\n/
length $data > 8192
Truth table33%1/3
A or B
A= $data =~ /\n/B= length $data > 8192
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | ($obj||$self)->fatal("invalid chunk header",0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # need more data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 6 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | # [3] must read chunk trailer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 11 | ▶ | if ( $rq->{rqchunked} == 3 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 4 | ▶ | $DEBUG && $rq->xdebug("want chunk trailer"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 4 | ▶ | if ( $data =~m{\A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | (?:\w[\w\-]*:.*\r?\n(?:[\t\040].*\r?\n)* )* # field:..+cont | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | \r?\n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | }xg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 4 | ▶ | $DEBUG && $rq->xdebug("request done (chunk trailer)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 4 | my $trailer = substr($data,0,pos($data),''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 4 | $self->{offset}[0] += length($trailer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 4 | $bytes += length($trailer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 4 | ▶ | $obj->in_chunk_trailer(0,$trailer,$time) if $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 4 | $rq->{state} |= RQBDY_DONE; # request done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | ▶ | } elsif ( $data =~m{\n\r?\n} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$data =~ /\n\r?\n/ or length $data > $self->{"hdr_maxsz"}[2]
MC/DC0%0/2
$data =~ /\n\r?\n/ or length $data > $self->{"hdr_maxsz"}[2]
$data =~ /\n\r?\n/
length $data > $self->{"hdr_maxsz"}[2]
Truth table0%0/3
A or B
A= $data =~ /\n\r?\n/B= length $data > $self->{"hdr_maxsz"}[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | or length($data) > $self->{hdr_maxsz}[2] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | ($obj||$self)->fatal("invalid chunk trailer",0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } elsif ( $eof ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # not fatal, because we got all data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | %TRACE && ($obj||$self)->xtrace( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | "eof before end of chunk trailer"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # need more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | $DEBUG && $rq->xdebug("need more bytes for chunk trailer"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | return $bytes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 37 | goto READ_DATA; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | # process response data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | sub _in1 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 37 | ▶ | my ($self,$data,$eof,$time) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_in1: called CC=127 SCAR=73.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 37 | my $rqs = $self->{requests}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 37 | my $bytes = 0; # processed bytes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 37 | ▶ | if ( ref($data)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # process gap in response data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 2 | ▶ | croak "unknown type $data->[0]" if $data->[0] ne 'gap'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 2 | my $len = $data->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 2 | ▶ | croak 'existing error in connection' if $self->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 2 | my $rqs = $self->{requests}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 2 | ▶ | croak 'no open response' if ! @$rqs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 2 | my $rq = $rqs->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 2 | ▶ | croak 'existing error in request' if $rq->{state} & RQ_ERROR; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | croak "gap too large" if $self->{gap_upto}[1]>=0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 2 | ▶ | && $self->{gap_upto}[1] < $self->{offset}[1] + $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"gap_upto"}[1] >= 0 and $self->{"gap_upto"}[1] < $self->{"offset"}[1] + $len
MC/DC0%0/2
$self->{"gap_upto"}[1] >= 0 and $self->{"gap_upto"}[1] < $self->{"offset"}[1] + $len
$self->{"gap_upto"}[1] >= 0
$self->{"gap_upto"}[1] < $self->{"offset"}[1] + $len
Truth table33%1/3
A and B
A= $self->{"gap_upto"}[1] >= 0B= $self->{"gap_upto"}[1] < $self->{"offset"}[1] + $len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 2 | ▶ | $rq->{rpclen} -= $len if defined $rq->{rpclen}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 2 | $self->{offset}[1] += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 2 | my $obj = $rq->{obj}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 2 | ▶ | if ($self->{upgrade}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | $self->{upgrade}(1,[ gap => $len ],$eof,$time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | ▶ | } elsif ($rq->{rpclen} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$rq->{"rpclen"} or not defined $rq->{"rpclen"} or $rq->{"rpchunked"}
$rq->{"rpclen"} or not defined $rq->{"rpclen"}
MC/DC0%0/3
$rq->{"rpclen"} or not defined $rq->{"rpclen"} or $rq->{"rpchunked"}
$rq->{"rpclen"}
not defined $rq->{"rpclen"}
$rq->{"rpchunked"}
Truth table25%1/4
A or not(B) or C
A= $rq->{"rpclen"}B= not defined $rq->{"rpclen"}C= $rq->{"rpchunked"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | or !defined $rq->{rpclen} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | or $rq->{rpchunked}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | $obj && $obj->in_response_body([ gap => $len ],$eof,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # done with request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 2 | ▶ | $DEBUG && $rq->xdebug("response done (last gap)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 2 | pop(@$rqs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 2 | ▶ | $obj && $obj->in_response_body([ gap => $len ],1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 2 | return $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | READ_DATA: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 60 | ▶ | return $bytes if $self->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 60 | ▶ | return $bytes if $data eq '' && !$eof; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$data eq "" and not $eof
MC/DC100%2/2
$data eq "" and not $eof
$data eq ""
not $eof
Truth table100%3/3
A and not(B)
A= $data eq ""B= not $eof
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 40 | ▶ | if ($self->{upgrade}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 5 | $self->{offset}[1] += length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 5 | $self->{upgrade}(1,$data,$eof,$time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 5 | return $bytes + length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 35 | ▶ | if ( $data eq '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 2 | ▶ | $DEBUG && $self->xdebug("no more data, eof=$eof bytes=$bytes"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # handle EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | # check if we got response body for last request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 2 | ▶ | if ( @$rqs && $rqs->[-1]{state} & RPBDY_DONE_ON_EOF ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
@$rqs and $rqs->[-1]{"state"} & 16
MC/DC0%0/2
@$rqs and $rqs->[-1]{"state"} & 16
@$rqs
$rqs->[-1]{"state"} & 16
Truth table33%1/3
A and B
A= @$rqsB= $rqs->[-1]{"state"} & 16
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | # response body done on eof | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 2 | my $rq = pop(@$rqs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 2 | ▶ | $DEBUG && $rq->xdebug("response done (eof)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 2 | ▶ | $rq->{obj}->in_response_body('',1,$time) if $rq->{obj}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } elsif ( @$rqs ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | # response body not done yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | my $rq = pop(@$rqs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | $DEBUG && $rq->xdebug("response done (unexpected eof)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | ▶ | if (($rq->{state} & RPHDR_DONE) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | if ($data eq '' and $self->{lastreqid}>1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$data eq "" and $self->{"lastreqid"} > 1
MC/DC0%0/2
$data eq "" and $self->{"lastreqid"} > 1
$data eq ""
$self->{"lastreqid"} > 1
Truth table0%0/3
A and B
A= $data eq ""B= $self->{"lastreqid"} > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | # We had already a request and now the server closes while | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # the client is still sending a new request. This happens | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | # with keep-alive connections and the client needs to handle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # this case with retrying the request. Signal this issue by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | # calling in_request_header with empty header. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | ($rq->{obj}||$self)->in_request_header('',$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$rq->{'obj'} || $self
MC/DC0%0/2
$rq->{'obj'} || $self
$rq->{'obj'}
$self
Truth table0%0/3
A || B
A= $rq->{'obj'}B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } elsif ($data eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | ($rq->{obj}||$self)->fatal( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$rq->{'obj'} || $self
MC/DC0%0/2
$rq->{'obj'} || $self
$rq->{'obj'}
$self
Truth table0%0/3
A || B
A= $rq->{'obj'}B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 'eof before receiving first response', 1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | %TRACE && ($rq->{obj}||$self)->xtrace( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rq->{'obj'} || $self
MC/DC0%0/2
$rq->{'obj'} || $self
$rq->{'obj'}
$self
Truth table0%0/3
A || B
A= $rq->{'obj'}B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | "eof within response header: '$data'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | ($rq->{obj}||$self)->fatal( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$rq->{'obj'} || $self
MC/DC0%0/2
$rq->{'obj'} || $self
$rq->{'obj'}
$self
Truth table0%0/3
A || B
A= $rq->{'obj'}B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 'eof within response header', 1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | # eof inside a response or close for first request already. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | %TRACE && ($rq->{obj}||$self)->xtrace("eof within response body"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$rq->{'obj'} || $self
MC/DC0%0/2
$rq->{'obj'} || $self
$rq->{'obj'}
$self
Truth table0%0/3
A || B
A= $rq->{'obj'}B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | ($rq->{obj}||$self)->fatal('eof within response body', 1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$rq->{'obj'} || $self
MC/DC0%0/2
$rq->{'obj'} || $self
$rq->{'obj'}
$self
Truth table0%0/3
A || B
A= $rq->{'obj'}B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 2 | return $bytes; # done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 33 | ▶ | if ( ! @$rqs ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | ▶ | if ( $data =~s{\A([\r\n]+)}{} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # skip newlines after request because newlines at beginning of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | # new request are allowed, stupid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | $bytes += length($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | goto READ_DATA; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | $self->fatal('data from server w/o request',1,$time); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 33 | my $rq = $rqs->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 33 | my $obj = $rq->{obj}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | # read response header if not done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 33 | ▶ | if ( not $rq->{state} & RPHDR_DONE ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 15 | ▶ | $DEBUG && $rq->xdebug("response header not read yet"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | # leading newlines at beginning of response are legally ignored junk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 15 | ▶ | if ( $data =~s{\A([\r\n]+)}{} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | ($obj||$self)->in_junk(1,$1,0,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | # no response header yet, check if data contains it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 15 | ▶ | if ( $data =~s{\A(.*?\n\r?\n)}{}s ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 14 | my $hdr = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 14 | my $n = length($hdr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 14 | $bytes += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 14 | $self->{offset}[1] += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 14 | my %hdr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 14 | my $err = parse_rsphdr($hdr,$rq->{request},\%hdr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 14 | ▶ | if ($err and my $sub = $obj->can('fix_rsphdr')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$err and my $sub = $obj->can("fix_rsphdr")
MC/DC0%0/2
$err and my $sub = $obj->can("fix_rsphdr")
$err
my $sub = $obj->can("fix_rsphdr")
Truth table66%2/3
A and B
A= $errB= my $sub = $obj->can("fix_rsphdr")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | $hdr = $sub->($obj,$hdr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | $err = parse_rsphdr($hdr,$rq->{request},\%hdr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 14 | ▶ | goto error if $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 13 | ▶ | $DEBUG && $rq->xdebug("got response header"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 13 | ▶ | %TRACE && $hdr{junk} && ($obj||$self)->xtrace( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
%Net::Inspect::L7::HTTP::TRACE and $hdr{"junk"}
$obj || $self
MC/DC0%0/2
%Net::Inspect::L7::HTTP::TRACE and $hdr{"junk"}
%Net::Inspect::L7::HTTP::TRACE
$hdr{"junk"}
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table33%1/3
A and B
A= %Net::Inspect::L7::HTTP::TRACEB= $hdr{"junk"}
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | "invalid request header data: $hdr{junk}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 13 | ▶ | if ($hdr{preliminary}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | # Preliminary response. Wait for read real response. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 1 | ▶ | $obj && $obj->in_response_header($hdr,$time,\%hdr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 1 | goto READ_DATA; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 12 | $rq->{state} |= RPHDR_DONE; # response header done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 12 | ▶ | if ($hdr{upgrade}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | # Reset length to undef since we need to read until eof. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 2 | $rq->{rpclen} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | # If no object is given we just use a dummy function which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | # returns the size of the data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | # If object has its own upgrade_XXXX method for the protocol we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # use this. Support for CONNECT has been traditionally built in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | # but can be redefined with upgrade_CONNECT. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 2 | ▶ | if (!$obj) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | $self->{upgrade} = sub {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | @{$self->{gap_upto}} = (-1,-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } elsif (my $sub = $obj->can('upgrade_'.$hdr{upgrade})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | # $sub might throw an error if it is unwilling to upgrade | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | # the connection based on request and response. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 1 | ▶ | unless ($self->{upgrade} = eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 1 | $sub->($obj,$self,$rq->{request},\%hdr) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | $err = "invalid connection upgrade '$hdr{upgrade}': $@"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | goto error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | } elsif ($sub = $obj->can('upgrade_ANY')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # $sub might throw an error if it is unwilling to upgrade | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | # the connection based on request and response. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | unless ($self->{upgrade} = eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | $sub->($obj,$self,$rq->{request},\%hdr,$hdr{upgrade}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | $err = "invalid connection upgrade '$hdr{upgrade}': $@"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | goto error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } elsif ($hdr{upgrade} eq 'CONNECT') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | # Traditionally just calls in_data. If this is not available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # call dummy function. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | $self->{upgrade} = $obj->can('in_data') && do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 1 | weaken(my $wobj = $obj); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 2 | ▶ | sub { $wobj->in_data(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 1 | ▶ | } || sub {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Condition33%2/6
$obj->can('in_data') && do {
builtin::weaken(my $wobj = $obj);
sub {
$wobj->in_data(@_);
}
} || sub {
}
$obj->can("in_data") and do {
builtin::weaken(my $wobj = $obj);
sub {
$wobj->in_data(@_);
}
}
MC/DC0%0/3
$obj->can('in_data') && do {
builtin::weaken(my $wobj = $obj);
sub {
$wobj->in_data(@_);
}
} || sub {
}
$obj->can("in_data")
do {
builtin::weaken(my $wobj = $obj);
sub {
$wobj->in_data(@_);
}
}
sub {
}
Truth table20%1/5
A and B || C
A= $obj->can("in_data")B= do {
builtin::weaken(my $wobj = $obj);
sub {
$wobj->in_data(@_);
}
}C= sub {
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 1 | @{$self->{gap_upto}} = (-1,-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | $err = "unsupported connection upgrade '$hdr{upgrade}'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | goto error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 2 | goto done; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } elsif ($rq->{request}{upgrade}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # The client requested an upgrade which the server did not ack. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | # Thus propagate the empty request body now. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | ▶ | $obj && $obj->in_request_body('',1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 10 | my $body_done; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 10 | ▶ | if ($hdr{chunked}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 2 | $rq->{rpchunked} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | } elsif (defined $hdr{content_length}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 6 | ▶ | if (($rq->{rpclen} = $hdr{content_length})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | # content_length > 0, can do gaps | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | $self->{gap_upto}[1]= $self->{offset}[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 3 | + $hdr{content_length}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 3 | $body_done = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | # no length given but method supports body -> end with eof | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 2 | $rq->{state} |= RPBDY_DONE_ON_EOF; # body done when eof | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 2 | $self->{gap_upto}[1] = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 12 | ▶ | done: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | $obj && $obj->in_response_header($hdr,$time,\%hdr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 12 | ▶ | if ($body_done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 3 | ▶ | $DEBUG && $rq->xdebug("response done (no body)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 3 | pop(@$rqs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 3 | ▶ | $obj && $obj->in_response_body('',1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 12 | goto READ_DATA; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | error: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 1 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 1 | ▶ | ($obj||$self)->fatal($err,1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table33%1/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 1 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } elsif ($data =~m{[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | ($obj||$self)->fatal( sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | "junk data instead of response header '%s...'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | substr($data,0,10)) ,1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | } elsif ( $data =~m{[^\n]\r?\n\r?\n}g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | ▶ | ($obj||$self)->fatal( sprintf("invalid response header syntax '%s'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | substr($data,0,pos($data))),1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } elsif ( length($data) > $self->{hdr_maxsz}[1] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | ▶ | ($obj||$self)->fatal('response header too big',1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | } elsif ( $eof ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 0 | ▶ | ($obj||$self)->fatal('eof in response header',1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | # will be called on new data from upper flow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 1 | ▶ | $DEBUG && $rq->xdebug("need more data for response header"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 1 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | # read response body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 18 | ▶ | if ( $data ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | # response body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 18 | ▶ | $DEBUG && $rq->xdebug("response body data"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | # have content-length or within chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 18 | ▶ | if ( my $want = $rq->{rpclen} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | # called for content-length or to read content from chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | # with known length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 6 | my $l = length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 6 | ▶ | if ( $l >= $want ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 5 | ▶ | $DEBUG && $rq->xdebug("need $want bytes, got all($l)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | # got all response body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 5 | my $body = substr($data,0,$want,''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 5 | $self->{offset}[1] += $want; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 5 | $bytes += $want; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 5 | $rq->{rpclen} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 5 | ▶ | if ( ! $rq->{rpchunked} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | # response done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 1 | pop(@$rqs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 1 | ▶ | $DEBUG && $rq->xdebug("response done (full clen received)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 1 | ▶ | $obj && $obj->in_response_body($body,1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 4 | ▶ | $obj->in_response_body($body,0,$time) if $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 4 | $rq->{rpchunked} = 2; # get CRLF after chunk | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | # only part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 1 | ▶ | $DEBUG && $rq->xdebug("need $want bytes, got only $l"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 1 | my $body = substr($data,0,$l,''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 1 | $self->{offset}[1] += $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 1 | $bytes += $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 1 | $rq->{rpclen} -= $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 1 | ▶ | $obj->in_response_body($body,0,$time) if $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | # no content-length, no chunk: must read until eof | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | } elsif ( $rq->{state} & RPBDY_DONE_ON_EOF ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 2 | ▶ | $DEBUG && $rq->xdebug("read until eof"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 2 | $self->{offset}[1] += length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 2 | $bytes += length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 2 | ▶ | if ($eof) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | # response done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | pop(@$rqs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 0 | ▶ | $DEBUG && $rq->xdebug("response done (eof)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 2 | ▶ | $obj->in_response_body($data,$eof,$time) if $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 2 | $data = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 2 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | # Chunking: rfc2616, 3.6.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | } elsif ( ! $rq->{rpchunked} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | # should not happen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 0 | die "no content-length and no chunked - why we are here?"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | # [2] must get CRLF after chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 10 | ▶ | if ( $rq->{rpchunked} == 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 4 | ▶ | $DEBUG && $rq->xdebug("want CRLF after chunk"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 4 | ▶ | if ( $data =~m{\A\r?\n}g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 4 | my $n = pos($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 4 | $self->{offset}[1] += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 4 | $bytes += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 4 | substr($data,0,$n,''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 4 | $rq->{rpchunked} = 1; # get next chunk header | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 4 | ▶ | $DEBUG && $rq->xdebug("got CRLF after chunk"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | } elsif ( length($data)>=2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 0 | ▶ | ($obj||$self)->fatal("no CRLF after chunk",1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | # need more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | # [1] must read chunk header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 10 | ▶ | if ( $rq->{rpchunked} == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 10 | ▶ | $DEBUG && $rq->xdebug("want chunk header"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 10 | ▶ | if ( $data =~m{\A([\da-fA-F]+)[ \t]*(?:;.*)?\r?\n}g ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 6 | $rq->{rpclen} = hex($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 6 | my $chdr = substr($data,0,pos($data),''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 6 | $self->{offset}[1] += length($chdr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 6 | $bytes += length($chdr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | $self->{gap_upto}[1] = $self->{offset}[1] + $rq->{rpclen} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | 6 | ▶ | if $rq->{rpclen}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 6 | ▶ | $obj->in_chunk_header(1,$chdr,$time) if $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 6 | ▶ | $DEBUG && $rq->xdebug( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | "got chunk header - want $rq->{rpclen} bytes"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 6 | ▶ | if ( ! $rq->{rpclen} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | # last chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 2 | $rq->{rpchunked} = 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 2 | ▶ | $obj && $obj->in_response_body('',1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | ▶ | } elsif ( $data =~m{\n} or length($data)>8192 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$data =~ /\n/ or length $data > 8192
MC/DC0%0/2
$data =~ /\n/ or length $data > 8192
$data =~ /\n/
length $data > 8192
Truth table33%1/3
A or B
A= $data =~ /\n/B= length $data > 8192
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 0 | ▶ | ($obj||$self)->fatal("invalid chunk header",1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | # need more data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 4 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | # [3] must read chunk trailer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 6 | ▶ | if ( $rq->{rpchunked} == 3 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 2 | ▶ | $DEBUG && $rq->xdebug("want chunk trailer"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 2 | ▶ | if ( $data =~m{\A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | (?:\w[\w\-]*:.*\r?\n(?:[\t\040].*\r?\n)* )* # field:..+cont | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | \r?\n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | }xg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 2 | ▶ | $DEBUG && $rq->xdebug("response done (chunk trailer)"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 2 | my $trailer = substr($data,0,pos($data),''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 2 | $self->{offset}[1] += length($trailer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 2 | $bytes += length($trailer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 2 | ▶ | $obj->in_chunk_trailer(1,$trailer,$time) if $obj; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 2 | pop(@$rqs); # done | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | ▶ | } elsif ( $data =~m{\n\r?\n} or | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$data =~ /\n\r?\n/ or length $data > $self->{"hdr_maxsz"}[2]
MC/DC0%0/2
$data =~ /\n\r?\n/ or length $data > $self->{"hdr_maxsz"}[2]
$data =~ /\n\r?\n/
length $data > $self->{"hdr_maxsz"}[2]
Truth table0%0/3
A or B
A= $data =~ /\n\r?\n/B= length $data > $self->{"hdr_maxsz"}[2]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | length($data)>$self->{hdr_maxsz}[2] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | ▶ | ($obj||$self)->fatal("invalid chunk trailer",1,$time); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$obj || $self
MC/DC0%0/2
$obj || $self
$obj
$self
Truth table0%0/3
A || B
A= $objB= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 0 | return $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | # need more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | ▶ | $DEBUG && $rq->xdebug("need more bytes for chunk trailer"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | return $bytes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 12 | goto READ_DATA; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | # parse and normalize header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | sub parse_hdrfields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 31 | ▶ | my ($hdr,$fields) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_hdrfields: called CC=8 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 31 | ▶ | return '' if ! defined $hdr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 18 | my $bad = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | parse: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 36 | ▶ | while ( $hdr =~m{\G$token_value_cont}gc ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 24 | ▶ | if ($3 eq '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | # no continuation line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 24 | push @{$fields->{ lc($1) }},$2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | # with continuation line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | my ($k,$v) = ($1,$2.$3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | # <space>value-part<space> -> ' ' + value-part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 0 | $v =~s{[\r\n]+[ \t](.*?)[ \t]*}{ $1}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | push @{$fields->{ lc($k) }},$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 36 | ▶ | if (pos($hdr)//0 != length($hdr)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
pos $hdr // 0 != length $hdr
MC/DC50%1/2
pos $hdr // 0 != length $hdr
pos $hdr
0 != length $hdr
Truth table66%2/3
A // B
A= pos $hdrB= 0 != length $hdr
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | # bad line inside | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 18 | ▶ | substr($hdr,0,pos($hdr)//0,''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
pos $hdr // 0
MC/DC0%0/1
pos $hdr // 0
pos $hdr
Truth table50%1/2
A
A= pos $hdr
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 18 | ▶ | $bad .= $1 if $hdr =~s{\A([^\n]*)\n}{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 18 | goto parse; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 18 | return $bad; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | sub parse_reqhdr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 17 | ▶ | my ($data,$hdr,$external_length) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_reqhdr: called CC=26 SCAR=36.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 17 | ▶ | $data =~m{\A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | ([A-Z]{2,20})[\040\t]+ # $1: method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | (\S+)[\040\t]+ # $2: path/URI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | HTTP/(1\.[01])[\40\t]* # $3: version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | \r?\n # (CR)LF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | ([^\r\n].*?\n)? # $4: fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | \r?\n # final (CR)LF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | \Z}sx or return "invalid request header"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 17 | my $version = $3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 17 | my $method = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 17 | %$hdr = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | url => $2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | version => $version, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | info => "$method $2 HTTP/$version", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | # fields - hash of fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | # junk - bad header fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | # expect - expectations from expect header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | # upgrade - { websocket => key } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | # content_length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | # chunked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 17 | my %kv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 17 | my $bad = parse_hdrfields($4,\%kv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 17 | ▶ | $hdr->{junk} = $bad if $bad ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 17 | $hdr->{fields} = \%kv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 17 | ▶ | if ($version>=1.1 and $kv{expect}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$version >= "1.1" and $kv{"expect"}
MC/DC100%2/2
$version >= "1.1" and $kv{"expect"}
$version >= "1.1"
$kv{"expect"}
Truth table100%3/3
A and B
A= $version >= "1.1"B= $kv{"expect"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | 1 | for(@{$kv{expect}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | # ignore all but 100-continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 1 | ▶ | $hdr->{expect}{lc($1)} = 1 if m{\b(100-continue)\b}i | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | # RFC2616 4.4.3: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | # chunked transfer-encoding takes preferece before content-length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 17 | ▶ | if ( $version >= 1.1 and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$version >= "1.1" and grep {/(?:^|[ \t,])chunked(?:$|[ \t,;])/i;} @{$kv{"transfer-encoding"} or [];}
MC/DC100%2/2
$version >= "1.1" and grep {/(?:^|[ \t,])chunked(?:$|[ \t,;])/i;} @{$kv{"transfer-encoding"} or [];}
$version >= "1.1"
grep {/(?:^|[ \t,])chunked(?:$|[ \t,;])/i;} @{$kv{"transfer-encoding"} or [];}
Truth table100%3/3
A and B
A= $version >= "1.1"B= grep {/(?:^|[ \t,])chunked(?:$|[ \t,;])/i;} @{$kv{"transfer-encoding"} or [];}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 4 | grep { m{(?:^|[ \t,])chunked(?:$|[ \t,;])}i } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 12 | ▶ | @{ $kv{'transfer-encoding'} || [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 4 | $hdr->{chunked} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | } elsif ( my $cl = $kv{'content-length'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | return "multiple different content-length header in request" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 5 | ▶ | if @$cl>1 and do { my %x; @x{@$cl} = (); keys(%x) } > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$cl > 1 and do {
my %x;
@x{@$cl} = ();
keys %x
} > 1
MC/DC0%0/2
@$cl > 1 and do {
my %x;
@x{@$cl} = ();
keys %x
} > 1
@$cl > 1
do {
my %x;
@x{@$cl} = ();
keys %x
} > 1
Truth table33%1/3
A and B
A= @$cl > 1B= do {
my %x;
@x{@$cl} = ();
keys %x
} > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 5 | ▶ | return "invalid content-length '$cl->[0]' in request" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | if $cl->[0] !~m{^(\d+)$}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 4 | $hdr->{content_length} = $cl->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 16 | ▶ | if ( $METHODS_WITHOUT_RQBODY{$method} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | # Complain if the client announced a body. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | return "no body allowed with $method" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 8 | ▶ | if $hdr->{content_length} or $hdr->{chunked}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$hdr->{"content_length"} or $hdr->{"chunked"}
MC/DC0%0/2
$hdr->{"content_length"} or $hdr->{"chunked"}
$hdr->{"content_length"}
$hdr->{"chunked"}
Truth table33%1/3
A or B
A= $hdr->{"content_length"}B= $hdr->{"chunked"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | } elsif ( $METHODS_WITH_RQBODY{$method} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | return "content-length or transfer-encoding chunked must be given with method $method" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | if ! $hdr->{chunked} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | and ! defined $hdr->{content_length} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 8 | ▶ | and ! $external_length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$hdr->{"chunked"} or defined $hdr->{"content_length"} or $external_length
$hdr->{"chunked"} or defined $hdr->{"content_length"}
MC/DC0%0/3
$hdr->{"chunked"} or defined $hdr->{"content_length"} or $external_length
$hdr->{"chunked"}
defined $hdr->{"content_length"}
$external_length
Truth table50%2/4
A or B or C
A= $hdr->{"chunked"}B= defined $hdr->{"content_length"}C= $external_length
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | } elsif ( ! $hdr->{chunked} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | # if not given content-length is considered 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 0 | ▶ | $hdr->{content_length} ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$hdr->{"content_length"} ||= 0
MC/DC0%0/1
$hdr->{"content_length"} ||= 0
$hdr->{"content_length"}
Truth table0%0/2
A
A= $hdr->{"content_length"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | # Connection upgrade | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 16 | ▶ | if ($version >= 1.1 and $kv{upgrade} and my %upgrade | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$version >= "1.1" and $kv{"upgrade"} and my(%upgrade) = map({lc $_, 1;} map({/($token)/g;} @{$kv{"upgrade"};}))
$version >= "1.1" and $kv{"upgrade"}
MC/DC66%2/3
$version >= "1.1" and $kv{"upgrade"} and my(%upgrade) = map({lc $_, 1;} map({/($token)/g;} @{$kv{"upgrade"};}))
$version >= "1.1"
$kv{"upgrade"}
my(%upgrade) = map({lc $_, 1;} map({/($token)/g;} @{$kv{"upgrade"};}))
Truth table75%3/4
A and B and C
A= $version >= "1.1"B= $kv{"upgrade"}C= my(%upgrade) = map({lc $_, 1;} map({/($token)/g;} @{$kv{"upgrade"};}))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 1 | = map { lc($_) => 1 } map { m{($token)}g } @{$kv{upgrade}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 1 | $hdr->{upgrade} = \%upgrade; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 16 | return; # no error | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | sub parse_rsphdr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 14 | ▶ | my ($data,$request,$hdr,$warn) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_rsphdr: called CC=29 SCAR=36.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 14 | ▶ | $data =~ m{\A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | HTTP/(1\.[01])[\040\t]+ # $1: version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | (\d\d\d) # $2: code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | (?:[\040\t]+([^\r\n]*))? # $3: reason | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | \r?\n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | ([^\r\n].*?\n)? # $4: fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | \r?\n # empty line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | \Z}sx or return "invalid response header"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 14 | my $version = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 14 | my $code = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 14 | %$hdr = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | version => $version, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | code => $code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | reason => $3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | # fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | # junk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | # content_length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | # chunked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | # upgrade | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | # preliminary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 14 | my %kv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 14 | my $bad = parse_hdrfields($4,\%kv); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 14 | $hdr->{fields} = \%kv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 14 | ▶ | $hdr->{junk} = $bad if $bad ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 14 | ▶ | if ($code<=199) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | # Preliminary responses do not contain any body. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 2 | $hdr->{preliminary} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 2 | $hdr->{content_length} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 2 | ▶ | if ($code == 100 and $request->{expect}{'100-continue'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$code == 100 and $request->{"expect"}{"100-continue"} or $code == 102 or $code == 101
$code == 100 and $request->{"expect"}{"100-continue"} or $code == 102
$code == 100 and $request->{"expect"}{"100-continue"}
MC/DC0%0/4
$code == 100 and $request->{"expect"}{"100-continue"} or $code == 102 or $code == 101
$code == 100
$request->{"expect"}{"100-continue"}
$code == 102
$code == 101
Truth table28%2/7
A and B or C or D
A= $code == 100B= $request->{"expect"}{"100-continue"}C= $code == 102D= $code == 101
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | or $code == 102 or $code == 101) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | # 100 should only happen with Expect: 100-continue from client | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 0 | ▶ | push @$warn,"unexpected intermediate status code $code" if $warn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | # Switching Protocols | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | # Any upgrade must have both a "Connection: upgrade" and a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | # "Upgrade: newprotocol" header. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 14 | ▶ | if ($code == 101) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 1 | my %proto; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 1 | ▶ | if ($request->{upgrade} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$request->{"upgrade"} and grep {/\bUPGRADE\b/i;} @{$kv{"connection"} or [];}
MC/DC0%0/2
$request->{"upgrade"} and grep {/\bUPGRADE\b/i;} @{$kv{"connection"} or [];}
$request->{"upgrade"}
grep {/\bUPGRADE\b/i;} @{$kv{"connection"} or [];}
Truth table33%1/3
A and B
A= $request->{"upgrade"}B= grep {/\bUPGRADE\b/i;} @{$kv{"connection"} or [];}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 1 | ▶ | and grep { m{\bUPGRADE\b}i } @{$kv{connection} || []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 1 | ▶ | for(@{$kv{upgrade} || []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | 1 | $proto{lc($_)} = 1 for split(m{\s*[,;]\s*}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 1 | ▶ | if (keys(%proto) == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | 1 | $hdr->{upgrade} = (keys %proto)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 1 | $hdr->{preliminary} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 1 | $hdr->{content_length} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 0 | return "invalid or unsupported connection upgrade"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | # successful response to CONNECT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 14 | ▶ | if ($request->{method} eq 'CONNECT' and $code >= 200 and $code < 300) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$request->{"method"} eq "CONNECT" and $code >= 200 and $code < 300
$request->{"method"} eq "CONNECT" and $code >= 200
MC/DC33%1/3
$request->{"method"} eq "CONNECT" and $code >= 200 and $code < 300
$request->{"method"} eq "CONNECT"
$code >= 200
$code < 300
Truth table50%2/4
A and B and C
A= $request->{"method"} eq "CONNECT"B= $code >= 200C= $code < 300
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 1 | $hdr->{upgrade} = 'CONNECT'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | 1 | $hdr->{content_length} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 1 | delete $hdr->{chunked}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | # RFC2616 4.4.3: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | # chunked transfer-encoding takes preferece before content-length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 13 | ▶ | if ( $version >= 1.1 and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$version >= "1.1" and grep {/(?:^|[ \t,])chunked(?:$|[ \t,;])/i;} @{$kv{"transfer-encoding"} or [];}
MC/DC100%2/2
$version >= "1.1" and grep {/(?:^|[ \t,])chunked(?:$|[ \t,;])/i;} @{$kv{"transfer-encoding"} or [];}
$version >= "1.1"
grep {/(?:^|[ \t,])chunked(?:$|[ \t,;])/i;} @{$kv{"transfer-encoding"} or [];}
Truth table100%3/3
A and B
A= $version >= "1.1"B= grep {/(?:^|[ \t,])chunked(?:$|[ \t,;])/i;} @{$kv{"transfer-encoding"} or [];}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 2 | grep { m{(?:^|[ \t,])chunked(?:$|[ \t,;])}i } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 9 | ▶ | @{ $kv{'transfer-encoding'} || [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 2 | $hdr->{chunked} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | } elsif ( my $cl = $kv{'content-length'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | return "multiple different content-length header in response" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 5 | ▶ | if @$cl>1 and do { my %x; @x{@$cl} = (); keys(%x) } > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@$cl > 1 and do {
my %x;
@x{@$cl} = ();
keys %x
} > 1
MC/DC0%0/2
@$cl > 1 and do {
my %x;
@x{@$cl} = ();
keys %x
} > 1
@$cl > 1
do {
my %x;
@x{@$cl} = ();
keys %x
} > 1
Truth table33%1/3
A and B
A= @$cl > 1B= do {
my %x;
@x{@$cl} = ();
keys %x
} > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 5 | ▶ | return "invalid content-length '$cl->[0]' in response" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | if $cl->[0] !~m{^(\d+)$}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 4 | $hdr->{content_length} = $cl->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 12 | ▶ | if ($CODE_WITHOUT_RPBODY{$code} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$CODE_WITHOUT_RPBODY{$code} or $METHODS_WITHOUT_RPBODY{$request->{"method"}}
MC/DC50%1/2
$CODE_WITHOUT_RPBODY{$code} or $METHODS_WITHOUT_RPBODY{$request->{"method"}}
$CODE_WITHOUT_RPBODY{$code}
$METHODS_WITHOUT_RPBODY{$request->{"method"}}
Truth table66%2/3
A or B
A= $CODE_WITHOUT_RPBODY{$code}B= $METHODS_WITHOUT_RPBODY{$request->{"method"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | or $METHODS_WITHOUT_RPBODY{$request->{method}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | # no content, even if specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 4 | $hdr->{content_length} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 4 | delete $hdr->{chunked}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 8 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | sub new_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_request: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 17 | return $self->{upper_flow}->new_request(@_,$self) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | # return open requests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | sub open_requests { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_requests: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 0 | ▶ | my @rq = @_ ? @{$self->{requests}}[@_] : @{$self->{requests}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 0 | ▶ | ? map { $_->{obj} ? ($_->{obj}):() } @rq | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | : 0 + @rq; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | sub fatal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 0 | ▶ | my ($self,$reason,$dir,$time) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fatal: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | 0 | ▶ | %TRACE && $self->xtrace($reason); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | sub xtrace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xtrace: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 0 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 0 | $msg = "$$.$self->{connid} $msg"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 0 | unshift @_,$msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 0 | goto &trace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | sub xdebug { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 0 | ▶ | $DEBUG or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xdebug: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 0 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 0 | $msg = "$$.$self->{connid} $msg"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 0 | unshift @_,$msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | 0 | goto &debug; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | sub dump_state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 0 | ▶ | $DEBUG or defined wantarray or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_state: not called CC=5 SCAR=34.0
Pod
documented
Branch: 1 branch
Condition0%0/3
$Net::Inspect::L7::HTTP::DEBUG or defined wantarray
MC/DC0%0/2
$Net::Inspect::L7::HTTP::DEBUG or defined wantarray
$Net::Inspect::L7::HTTP::DEBUG
defined wantarray
Truth table0%0/3
A or B
A= $Net::Inspect::L7::HTTP::DEBUGB= defined wantarray
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 0 | my $m = $self->{meta}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | my $msg = sprintf("%s.%d -> %s.%d ", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 0 | $m->{saddr},$m->{sport},$m->{daddr},$m->{dport}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 0 | my $rqs = $self->{requests}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | 0 | ▶ | for( my $i=0;$i<@$rqs;$i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | $msg .= sprintf("request#$i state=%05b %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 0 | $rqs->[$i]{state},$rqs->[$i]{request}{info}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 0 | ▶ | return $msg if defined wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 0 | $self->xdebug($msg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | package Net::Inspect::L7::HTTP::_DebugRequest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | sub xdebug { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 0 | ▶ | my $rq = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xdebug: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 0 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 0 | unshift @_, $rq->{conn}, "#$rq->{reqid} $msg"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | goto &Net::Inspect::L7::HTTP::xdebug; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||