| 1 | # You may distribute under the terms of either the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # or the Artistic License (the same terms as Perl itself) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # (C) Paul Evans, 2008-2023 -- leonerd@leonerd.org.uk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | package Net::Async::HTTP::Connection 0.50; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 38 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 38 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 38 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 38 | ▶ | use base qw( IO::Async::Stream ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 38 | IO::Async::Stream->VERSION( '0.59' ); # ->write( ..., on_write ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 38 | ▶ | use Net::Async::HTTP::StallTimer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 38 | ▶ | use HTTP::Response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 38 | my $CRLF = "\x0d\x0a"; # More portable than \r\n | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 38 | ▶ | use Struct::Dumb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 38 | struct RequestContext => [qw( req on_read stall_timer resp_header resp_bytes on_done is_done f )], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | named_constructor => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Detect whether HTTP::Message properly trims whitespace in header values. If | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # it doesn't, we have to deploy a workaround to fix them up. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # https://rt.cpan.org/Ticket/Display.html?id=75224 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 38 | ▶ | use constant HTTP_MESSAGE_TRIMS_LWS => HTTP::Message->parse( "Name: value " )->header("Name") eq "value"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | C<Net::Async::HTTP::Connection> - HTTP client protocol handler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | This class provides a connection to a single HTTP server, and is used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | internally by L<Net::Async::HTTP>. It is not intended for general use. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | sub _init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 101 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 101 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 101 | $self->SUPER::_init( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 101 | $self->{requests_in_flight} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | sub configure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 289 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 289 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 289 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 289 | foreach (qw( pipeline max_in_flight ready_queue decode_content is_proxy )) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1445 | ▶ | $self->{$_} = delete $params{$_} if exists $params{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 289 | ▶ | if( my $on_closed = $params{on_closed} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 68 | ▶ | $params{on_closed} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 68 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 68 | $self->debug_printf( "CLOSED in-flight=$self->{requests_in_flight}" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 68 | $self->error_all( "Connection closed" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 68 | undef $self->{ready_queue}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 68 | $on_closed->( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 101 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 289 | ▶ | croak "max_in_flight parameter required, may be zero" unless defined $self->{max_in_flight}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 289 | $self->SUPER::configure( %params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | sub should_pipeline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 206 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
should_pipeline: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 206 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | return $self->{pipeline} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | $self->{can_pipeline} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 206 | ▶ | ( !$self->{max_in_flight} || $self->{requests_in_flight} < $self->{max_in_flight} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition88%8/9
$self->{'pipeline'} && $self->{'can_pipeline'} && (!$self->{'max_in_flight'} || $self->{'requests_in_flight'} < $self->{'max_in_flight'})
$self->{"pipeline"} and $self->{"can_pipeline"}
not $self->{"max_in_flight"} or $self->{"requests_in_flight"} < $self->{"max_in_flight"}
MC/DC75%3/4
$self->{'pipeline'} && $self->{'can_pipeline'} && (!$self->{'max_in_flight'} || $self->{'requests_in_flight'} < $self->{'max_in_flight'})
$self->{"pipeline"}
$self->{"can_pipeline"}
not $self->{"max_in_flight"}
$self->{"requests_in_flight"} < $self->{"max_in_flight"}
Truth table80%4/5
A and B && not(C) or D
A= $self->{"pipeline"}B= $self->{"can_pipeline"}C= not $self->{"max_in_flight"}D= $self->{"requests_in_flight"} < $self->{"max_in_flight"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | sub connect | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 101 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
connect: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 101 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 101 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 101 | ▶ | my $key = defined $args{path} ? $args{path} : "$args{host}:$args{service}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 101 | $self->debug_printf( "CONNECT $key" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 101 | ▶ | defined wantarray or die "VOID ->connect"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | $self->SUPER::connect( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | socktype => "stream", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | %args | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 93 | ▶ | )->on_done( sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 93 | $self->debug_printf( "CONNECTED" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 101 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | sub ready | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 209 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ready: called CC=13 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 209 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 209 | ▶ | my $queue = $self->{ready_queue} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 187 | ▶ | if( $self->should_pipeline ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 79 | $self->debug_printf( "READY pipelined" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 79 | ▶ | while( @$queue && $self->should_pipeline ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$queue and $self->should_pipeline
MC/DC100%2/2
@$queue and $self->should_pipeline
@$queue
$self->should_pipeline
Truth table100%3/3
A and B
A= @$queueB= $self->should_pipeline
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 18 | my $ready = shift @$queue; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 18 | my $f = $ready->future; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 18 | ▶ | next if $f->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 17 | ▶ | $ready->connecting and $ready->connecting->cancel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 17 | $f->done( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ▶ | elsif( @$queue and $self->is_idle ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
@$queue and $self->is_idle
MC/DC50%1/2
@$queue and $self->is_idle
@$queue
$self->is_idle
Truth table66%2/3
A and B
A= @$queueB= $self->is_idle
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 100 | $self->debug_printf( "READY non-pipelined" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 100 | ▶ | while( @$queue ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 100 | my $ready = shift @$queue; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 100 | my $f = $ready->future; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 100 | ▶ | next if $f->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 100 | ▶ | $ready->connecting and $ready->connecting->cancel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 100 | $f->done( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 100 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 8 | ▶ | $self->debug_printf( "READY cannot-run queue=%d idle=%s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | scalar @$queue, $self->is_idle ? "Y" : "N"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | sub is_idle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 159 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_idle: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 159 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 159 | return $self->{requests_in_flight} == 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | sub on_read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 249 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_read: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 249 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 249 | my ( $buffref, $closed ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 249 | ▶ | while( my $head = $self->{request_queue}[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 219 | ▶ | shift @{ $self->{request_queue} } and next if $head->is_done; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$head->is_done && (shift @{$$self{'request_queue'};} && (next))
shift @{$$self{"request_queue"};} and next
MC/DC0%0/2
$head->is_done && (shift @{$$self{'request_queue'};} && (next))
$head->is_done
shift @{$$self{"request_queue"};}
Truth table33%1/3
A && B
A= $head->is_doneB= shift @{$$self{"request_queue"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 218 | ▶ | $head->stall_timer->reset if $head->stall_timer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 218 | my $ret = $head->on_read->( $self, $buffref, $closed, $head ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 217 | ▶ | if( defined $ret ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 102 | ▶ | return $ret if !ref $ret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 70 | $head->on_read = $ret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 70 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 115 | ▶ | $head->is_done or die "ARGH: undef return without being marked done"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 115 | shift @{ $self->{request_queue} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 115 | ▶ | return 1 if !$closed and length $$buffref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $closed and length $$buffref
MC/DC100%2/2
not $closed and length $$buffref
not $closed
length $$buffref
Truth table100%3/3
not(A) and B
A= not $closedB= length $$buffref
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 113 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # Reinvoked after switch back to baseline, but may be idle again | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 31 | ▶ | return if $closed or !length $$buffref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$closed or not length $$buffref
MC/DC50%1/2
$closed or not length $$buffref
$closed
not length $$buffref
Truth table66%2/3
A or not(B)
A= $closedB= not length $$buffref
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | $self->invoke_error( "Spurious on_read of connection while idle", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | http_connection => read => $$buffref ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | $$buffref = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | sub on_write_eof | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_write_eof: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $self->error_all( "Connection closed", http => undef, undef ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | sub error_all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 68 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error_all: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 68 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 68 | ▶ | while( my $head = shift @{ $self->{request_queue} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 35 | ▶ | $head->f->fail( @_ ) unless $head->is_done or $head->f->is_ready; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$head->is_done or $head->f->is_ready
MC/DC100%2/2
$head->is_done or $head->f->is_ready
$head->is_done
$head->f->is_ready
Truth table100%3/3
A or B
A= $head->is_doneB= $head->f->is_ready
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | sub request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 130 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: called CC=27 SCAR=33.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 130 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 130 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 130 | ▶ | my $on_header = $args{on_header} or croak "Expected 'on_header' as a CODE ref"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 130 | my $req = $args{request}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 130 | ▶ | ref $req and $req->isa( "HTTP::Request" ) or croak "Expected 'request' as a HTTP::Request reference"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $req and $req->isa("HTTP::Request")
MC/DC0%0/2
ref $req and $req->isa("HTTP::Request")
ref $req
$req->isa("HTTP::Request")
Truth table33%1/3
A and B
A= ref $reqB= $req->isa("HTTP::Request")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 130 | $self->debug_printf( "REQUEST %s %s", $req->method, $req->uri ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 130 | my $request_body = $args{request_body}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 130 | my $expect_continue = !!$args{expect_continue}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 130 | my $method = $req->method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 130 | ▶ | if( $method eq "POST" or $method eq "PUT" or length $req->content ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$method eq "POST" or $method eq "PUT" or length $req->content
$method eq "POST" or $method eq "PUT"
MC/DC100%3/3
$method eq "POST" or $method eq "PUT" or length $req->content
$method eq "POST"
$method eq "PUT"
length $req->content
Truth table100%4/4
A or B or C
A= $method eq "POST"B= $method eq "PUT"C= length $req->content
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 13 | $req->init_header( "Content-Length", length $req->content ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 130 | ▶ | if( $expect_continue ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | $req->init_header( "Expect", "100-continue" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 130 | ▶ | if( $self->{decode_content} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | #$req->init_header( "Accept-Encoding", Net::Async::HTTP->can_decode ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | $req->init_header( "Accept-Encoding", "gzip" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 130 | my $f = $self->loop->new_future | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | ->set_label( "$method " . $req->uri ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # TODO: Cancelling a request Future shouldn't necessarily close the socket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # if we haven't even started writing the request yet. But we can't know | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # that currently. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 5 | ▶ | $f->on_cancel( sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | $self->debug_printf( "CLOSE on_cancel" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | $self->close_now; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 130 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 130 | my $stall_timer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 130 | ▶ | if( $args{stall_timeout} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | $stall_timer = Net::Async::HTTP::StallTimer->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | delay => $args{stall_timeout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | future => $f, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 4 | $self->add_child( $stall_timer ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # Don't start it yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | ▶ | my $remove_timer = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 4 | ▶ | $self->remove_child( $stall_timer ) if $stall_timer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | undef $stall_timer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | $f->on_ready( $remove_timer ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 130 | push @{ $self->{request_queue} }, my $ctx = RequestContext( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | req => $req, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | on_read => undef, # will be set later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | stall_timer => $stall_timer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | resp_header => undef, # will be set later | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | resp_bytes => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | on_done => $args{on_done}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 130 | is_done => 0, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | f => $f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 130 | my $on_body_write; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 130 | ▶ | if( $stall_timer or $args{on_body_write} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$stall_timer or $args{"on_body_write"}
MC/DC100%2/2
$stall_timer or $args{"on_body_write"}
$stall_timer
$args{"on_body_write"}
Truth table100%3/3
A or B
A= $stall_timerB= $args{"on_body_write"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 5 | my $inner_on_body_write = $args{on_body_write}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 5 | my $written = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 10 | ▶ | $on_body_write = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 10 | ▶ | $stall_timer->reset if $stall_timer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 10 | ▶ | $inner_on_body_write->( $written += $_[1] ) if $inner_on_body_write; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 4 | ▶ | my $write_request_body = defined $request_body ? sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 4 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 4 | $self->write( $request_body, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | on_write => $on_body_write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 130 | ▶ | } : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # Unless the request method is CONNECT, or we are connecting to a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # non-transparent proxy, the URL is not allowed to contain | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # an authority; only path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # Take a copy of the headers since we'll be hacking them up | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 130 | my $headers = $req->headers->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 130 | my $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 130 | ▶ | if( $method eq "CONNECT" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $path = $req->uri->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 130 | my $uri = $req->uri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 130 | ▶ | if ( $self->{is_proxy} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 2 | $path = $uri->as_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 128 | $path = $uri->path_query; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 128 | ▶ | $path = "/$path" unless $path =~ m{^/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 130 | my $authority = $uri->authority; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 130 | ▶ | if( defined $authority and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $authority and () = $authority =~ /^(.*?):(.*)@(.*)$/u
MC/DC100%2/2
defined $authority and () = $authority =~ /^(.*?):(.*)@(.*)$/u
defined $authority
() = $authority =~ /^(.*?):(.*)@(.*)$/u
Truth table100%3/3
A and B
A= defined $authorityB= () = $authority =~ /^(.*?):(.*)@(.*)$/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | my ( $user, $pass, $host ) = $authority =~ m/^(.*?):(.*)@(.*)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | $headers->init_header( Host => $host ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | $headers->authorization_basic( $user, $pass ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 128 | $headers->init_header( Host => $authority ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 130 | ▶ | my $protocol = $req->protocol || "HTTP/1.1"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$req->protocol || 'HTTP/1.1'
MC/DC100%1/1
$req->protocol || 'HTTP/1.1'
$req->protocol
Truth table100%2/2
A
A= $req->protocol
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 130 | my @headers = ( "$method $path $protocol" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 312 | ▶ | $headers->scan( sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 312 | my ( $name, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 312 | $name =~ s/^://; # non-canonical header | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 312 | push @headers, "$name: $value"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 130 | } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 130 | ▶ | $stall_timer->start if $stall_timer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 130 | ▶ | $stall_timer->reason = "writing request" if $stall_timer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 130 | ▶ | my $on_header_write = $stall_timer ? sub { $stall_timer->reset } : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 130 | $self->write( join( $CRLF, @headers ) . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | $CRLF . $CRLF, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | on_write => $on_header_write ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 130 | ▶ | $self->write( $req->content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | on_write => $on_body_write ) if length $req->content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 130 | ▶ | $write_request_body->( $self ) if $write_request_body and !$expect_continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$write_request_body and not $expect_continue
MC/DC100%2/2
$write_request_body and not $expect_continue
$write_request_body
not $expect_continue
Truth table100%3/3
A and not(B)
A= $write_request_bodyB= not $expect_continue
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 3 | ▶ | $self->write( "", on_flush => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 3 | ▶ | return unless $stall_timer; # test again in case it was cancelled in the meantime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 3 | $stall_timer->reset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 3 | $stall_timer->reason = "waiting for response"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 130 | ▶ | }) if $stall_timer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 130 | $self->{requests_in_flight}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | $ctx->on_read = $self->_mk_on_read_header( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 130 | ▶ | $args{previous_response}, $expect_continue ? $write_request_body : undef, $on_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 130 | return $f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | sub _mk_on_read_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 130 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mk_on_read_header: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 130 | shift; # $self | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 130 | my ( $previous_response, $write_request_body, $on_header ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 122 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=34 SCAR=36.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 122 | my ( $self, $buffref, $closed, $ctx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 122 | my $req = $ctx->req; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 122 | my $stall_timer = $ctx->stall_timer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 122 | my $f = $ctx->f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 122 | ▶ | if( $stall_timer ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | $stall_timer->reason = "receiving response header"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | $stall_timer->reset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 122 | ▶ | if( length $$buffref >= 4 and $$buffref !~ m/^HTTP/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $$buffref >= 4 and not $$buffref =~ /^HTTP/u
MC/DC100%2/2
length $$buffref >= 4 and not $$buffref =~ /^HTTP/u
length $$buffref >= 4
not $$buffref =~ /^HTTP/u
Truth table100%3/3
A and not(B)
A= length $$buffref >= 4B= not $$buffref =~ /^HTTP/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | $self->debug_printf( "ERROR fail" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | ▶ | $f->fail( "Did not receive HTTP response from server", http => undef, $req ) unless $f->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | $self->close_now; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 122 | ▶ | unless( $$buffref =~ s/^(.*?$CRLF$CRLF)//s ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 3 | ▶ | if( $closed ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | $self->debug_printf( "ERROR closed" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | ▶ | $f->fail( "Connection closed while awaiting header", http => undef, $req ) unless $f->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | $self->close_now; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 3 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 119 | $ctx->resp_bytes += $+[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 119 | my $header = HTTP::Response->parse( $1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # HTTP::Response doesn't strip the \rs from this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 119 | ( my $status_line = $header->status_line ) =~ s/\r$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 119 | $ctx->resp_header = $header; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 119 | unless( HTTP_MESSAGE_TRIMS_LWS ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 119 | my @headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 242 | ▶ | $header->scan( sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 242 | my ( $name, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 242 | s/^\s+//, s/\s+$// for $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 242 | push @headers, $name => $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 119 | } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 119 | ▶ | $header->header( @headers ) if @headers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 119 | my $protocol = $header->protocol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 119 | ▶ | if( $protocol =~ m{^HTTP/1\.(\d+)$} and $1 >= 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$protocol =~ m[^HTTP/1\.(\d+)$]u and $1 >= 1
MC/DC50%1/2
$protocol =~ m[^HTTP/1\.(\d+)$]u and $1 >= 1
$protocol =~ m[^HTTP/1\.(\d+)$]u
$1 >= 1
Truth table66%2/3
A and B
A= $protocol =~ m[^HTTP/1\.(\d+)$]uB= $1 >= 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 112 | $self->{can_pipeline} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 119 | ▶ | if( $header->code =~ m/^1/ ) { # 1xx is not a final response | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1 | $self->debug_printf( "HEADER [provisional] %s", $status_line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 1 | ▶ | $write_request_body->( $self ) if $write_request_body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 118 | $header->request( $req ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 118 | ▶ | $header->previous( $previous_response ) if $previous_response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 118 | $self->debug_printf( "HEADER %s", $status_line ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 118 | my $on_body_chunk = $on_header->( $header ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 118 | my $code = $header->code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 118 | my $content_encoding = $header->header( "Content-Encoding" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 118 | my $decoder; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 118 | ▶ | if( $content_encoding and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$content_encoding and $decoder = "Net::Async::HTTP"->can_decode($content_encoding)
MC/DC50%1/2
$content_encoding and $decoder = "Net::Async::HTTP"->can_decode($content_encoding)
$content_encoding
$decoder = "Net::Async::HTTP"->can_decode($content_encoding)
Truth table66%2/3
A and B
A= $content_encodingB= $decoder = "Net::Async::HTTP"->can_decode($content_encoding)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | $decoder = Net::Async::HTTP->can_decode( $content_encoding ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 2 | $header->init_header( "X-Original-Content-Encoding" => $header->remove_header( "Content-Encoding" ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # can_pipeline is set for HTTP/1.1 or above; presume it can keep-alive if set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 118 | ▶ | my $connection_close = lc( $header->header( "Connection" ) || ( $self->{can_pipeline} ? "keep-alive" : "close" ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$header->header('Connection') || ($self->{'can_pipeline'} ? 'keep-alive' : 'close')
MC/DC0%0/2
$header->header('Connection') || ($self->{'can_pipeline'} ? 'keep-alive' : 'close')
$header->header('Connection')
($self->{'can_pipeline'} ? 'keep-alive' : 'close')
Truth table66%2/3
A || B
A= $header->header('Connection')B= ($self->{'can_pipeline'} ? 'keep-alive' : 'close')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | eq "close"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 118 | ▶ | if( $connection_close ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 22 | $self->{max_in_flight} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | ▶ | elsif( defined( my $keep_alive = lc( $header->header("Keep-Alive") || "" ) ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$header->header('Keep-Alive') || ''
MC/DC0%0/1
$header->header('Keep-Alive') || ''
$header->header('Keep-Alive')
Truth table50%1/2
A
A= $header->header('Keep-Alive')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 96 | my ( $max ) = ( $keep_alive =~ m/max=(\d+)/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 96 | ▶ | $self->{max_in_flight} = $max if $max && $max < $self->{max_in_flight}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$max and $max < $self->{"max_in_flight"}
MC/DC0%0/2
$max and $max < $self->{"max_in_flight"}
$max
$max < $self->{"max_in_flight"}
Truth table33%1/3
A and B
A= $maxB= $max < $self->{"max_in_flight"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 83 | ▶ | my $on_more = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 83 | my ( $chunk ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 83 | ▶ | if( $decoder and not eval { $chunk = $decoder->( $chunk ); 1 } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$decoder and not eval {
do {
$chunk = &$decoder($chunk);
1
}
}
MC/DC0%0/2
$decoder and not eval {
do {
$chunk = &$decoder($chunk);
1
}
}
$decoder
not eval {
do {
$chunk = &$decoder($chunk);
1
}
}
Truth table66%2/3
A and not(B)
A= $decoderB= not eval {
do {
$chunk = &$decoder($chunk);
1
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | $self->debug_printf( "ERROR decode failed" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $f->fail( "Decode error $@", http => undef, $req ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | $self->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 83 | $on_body_chunk->( $chunk ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 83 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 118 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 116 | ▶ | my $on_done = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 116 | my ( $ctx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 116 | $ctx->is_done++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # TODO: IO::Async probably ought to do this. We need to fire the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # on_closed event _before_ calling on_body_chunk, to clear the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # connection cache in case another request comes - e.g. HEAD->GET | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 116 | ▶ | $self->close if $connection_close; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 116 | my $final; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 116 | ▶ | if( $decoder and not eval { $final = $decoder->(); 1 } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$decoder and not eval {
do {
$final = &$decoder();
1
}
}
MC/DC0%0/2
$decoder and not eval {
do {
$final = &$decoder();
1
}
}
$decoder
not eval {
do {
$final = &$decoder();
1
}
}
Truth table66%2/3
A and not(B)
A= $decoderB= not eval {
do {
$final = &$decoder();
1
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | $self->debug_printf( "ERROR decode failed" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | $f->fail( "Decode error $@", http => undef, $req ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | $self->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 116 | ▶ | $on_body_chunk->( $final ) if defined $final and length $final; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $final and length $final
MC/DC0%0/2
defined $final and length $final
defined $final
length $final
Truth table66%2/3
A and B
A= defined $finalB= length $final
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 116 | my $response = $on_body_chunk->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 116 | ▶ | my $e = eval { $f->done( $response ) unless $f->is_cancelled; 1 } ? undef : $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 116 | ▶ | $ctx->on_done->( $ctx ) if $ctx->on_done; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 116 | $self->{requests_in_flight}--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 116 | $self->debug_printf( "DONE remaining in-flight=$self->{requests_in_flight}" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 116 | $self->ready; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 116 | ▶ | if( defined $e ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 2 | chomp $e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 2 | $self->invoke_error( $e, perl => ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # This might not return, if it top-level croaks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 115 | return undef; # Finished | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 118 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | # RFC 2616 says "HEAD" does not have a body, nor do any 1xx codes, nor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # 204 (No Content) nor 304 (Not Modified) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 118 | ▶ | if( $req->method eq "HEAD" or $code =~ m/^1..$/ or $code eq "204" or $code eq "304" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$req->method eq "HEAD" or $code =~ /^1..$/u or $code eq 204 or $code eq 304
$req->method eq "HEAD" or $code =~ /^1..$/u or $code eq 204
$req->method eq "HEAD" or $code =~ /^1..$/u
MC/DC50%2/4
$req->method eq "HEAD" or $code =~ /^1..$/u or $code eq 204 or $code eq 304
$req->method eq "HEAD"
$code =~ /^1..$/u
$code eq 204
$code eq 304
Truth table60%3/5
A or B or C or D
A= $req->method eq "HEAD"B= $code =~ /^1..$/uC= $code eq 204D= $code eq 304
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 3 | $self->debug_printf( "BODY done [none]" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 3 | return $on_done->( $ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 115 | my $transfer_encoding = $header->header( "Transfer-Encoding" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 115 | my $content_length = $header->content_length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 115 | ▶ | if( defined $transfer_encoding and $transfer_encoding eq "chunked" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $transfer_encoding and $transfer_encoding eq "chunked"
MC/DC50%1/2
defined $transfer_encoding and $transfer_encoding eq "chunked"
defined $transfer_encoding
$transfer_encoding eq "chunked"
Truth table66%2/3
A and B
A= defined $transfer_encodingB= $transfer_encoding eq "chunked"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 4 | $self->debug_printf( "BODY chunks" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 4 | ▶ | $stall_timer->reason = "receiving body chunks" if $stall_timer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 4 | return $self->_mk_on_read_chunked( $on_more, $on_done ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | elsif( defined $content_length ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 99 | $self->debug_printf( "BODY length $content_length" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 99 | ▶ | if( $content_length == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 48 | $self->debug_printf( "BODY done [length=0]" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 48 | return $on_done->( $ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 51 | ▶ | $stall_timer->reason = "receiving body" if $stall_timer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 51 | return $self->_mk_on_read_length( $content_length, $on_more, $on_done ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 12 | $self->debug_printf( "BODY until EOF" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 12 | ▶ | $stall_timer->reason = "receiving body until EOF" if $stall_timer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 12 | return $self->_mk_on_read_until_eof( $on_more, $on_done ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 130 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | sub _mk_on_read_chunked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mk_on_read_chunked: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 4 | shift; # $self | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 4 | my ( $on_more, $on_done ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 4 | my $chunk_length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 16 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=29.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 16 | my ( $self, $buffref, $closed, $ctx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 16 | my $req = $ctx->req; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 16 | my $f = $ctx->f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 16 | ▶ | if( !defined $chunk_length and $$buffref =~ s/^(.*?)$CRLF// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $chunk_length and $$buffref =~ s/^(.*?)$CRLF//u
MC/DC50%1/2
not defined $chunk_length and $$buffref =~ s/^(.*?)$CRLF//u
not defined $chunk_length
$$buffref =~ s/^(.*?)$CRLF//u
Truth table66%2/3
not(A) and B
A= not defined $chunk_lengthB= $$buffref =~ s/^(.*?)$CRLF//u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 10 | my $header = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 10 | $ctx->resp_bytes += $+[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | # Chunk header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 10 | ▶ | unless( $header =~ s/^([A-Fa-f0-9]+).*// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | ▶ | $f->fail( "Corrupted chunk header", http => undef, $req ) unless $f->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 1 | $self->close_now; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 9 | $chunk_length = hex( $1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 9 | ▶ | return 1 if $chunk_length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 3 | return $self->_mk_on_read_chunk_trailer( $req, $on_more, $on_done, $f ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # Chunk is followed by a CRLF, which isn't counted in the length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 6 | ▶ | if( defined $chunk_length and length( $$buffref ) >= $chunk_length + 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $chunk_length and length $$buffref >= $chunk_length + 2
MC/DC0%0/2
defined $chunk_length and length $$buffref >= $chunk_length + 2
defined $chunk_length
length $$buffref >= $chunk_length + 2
Truth table33%1/3
A and B
A= defined $chunk_lengthB= length $$buffref >= $chunk_length + 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # Chunk body | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 6 | my $chunk = substr( $$buffref, 0, $chunk_length, "" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 6 | $ctx->resp_bytes += length $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 6 | ▶ | unless( $$buffref =~ s/^$CRLF// ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 0 | $self->debug_printf( "ERROR chunk without CRLF" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | $f->fail( "Chunk of size $chunk_length wasn't followed by CRLF", http => undef, $req ) unless $f->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | $self->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 6 | $ctx->resp_bytes += $+[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 6 | undef $chunk_length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 6 | return $on_more->( $chunk ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | ▶ | if( $closed ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | $self->debug_printf( "ERROR closed" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | ▶ | $f->fail( "Connection closed while awaiting chunk", http => undef, $req ) unless $f->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 4 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | sub _mk_on_read_chunk_trailer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mk_on_read_chunk_trailer: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 3 | shift; # $self | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 3 | my ( undef, $on_more, $on_done ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 3 | my $trailer = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 3 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 3 | my ( $self, $buffref, $closed, $ctx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 3 | my $req = $ctx->req; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 3 | my $f = $ctx->f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 3 | ▶ | if( $closed ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | $self->debug_printf( "ERROR closed" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | $f->fail( "Connection closed while awaiting chunk trailer", http => undef, $req ) unless $f->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 3 | ▶ | $$buffref =~ s/^(.*)$CRLF// or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 3 | $trailer .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 3 | $ctx->resp_bytes += $+[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 3 | ▶ | return 1 if length $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # TODO: Actually use the trailer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 3 | $self->debug_printf( "BODY done [chunked]" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 3 | return $on_done->( $ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | sub _mk_on_read_length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 51 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mk_on_read_length: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 51 | shift; # $self | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 51 | my ( $content_length, $on_more, $on_done ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 52 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 52 | my ( $self, $buffref, $closed, $ctx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 52 | my $req = $ctx->req; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 52 | my $f = $ctx->f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | # This will truncate it if the server provided too much | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 52 | my $content = substr( $$buffref, 0, $content_length, "" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 52 | $content_length -= length $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 52 | $ctx->resp_bytes += length $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 52 | ▶ | return undef unless $on_more->( $content ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 52 | ▶ | if( $content_length == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 50 | $self->debug_printf( "BODY done [length]" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 50 | return $on_done->( $ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 2 | ▶ | if( $closed ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | $self->debug_printf( "ERROR closed" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | $f->fail( "Connection closed while awaiting body", http => undef, $req ) unless $f->is_cancelled; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 2 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 51 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | sub _mk_on_read_until_eof | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mk_on_read_until_eof: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 12 | shift; # $self | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 12 | my ( $on_more, $on_done ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 25 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 25 | my ( $self, $buffref, $closed, $ctx ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 25 | my $content = $$buffref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 25 | $$buffref = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 25 | $ctx->resp_bytes += length $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 25 | ▶ | return undef unless $on_more->( $content ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 25 | ▶ | return 0 unless $closed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 12 | $self->debug_printf( "BODY done [eof]" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 12 | return $on_done->( $ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 38 | 0x55AA; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||