| 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, 2013-2023 -- leonerd@leonerd.org.uk | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | package Net::Async::HTTP::Server::Protocol 0.15; | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use base qw( IO::Async::Stream ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use Scalar::Util qw( weaken ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 13 | my $CRLF = "\x0d\x0a"; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | sub on_read | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 56 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_read: called CC=7 SCAR=20.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 56 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 56 | my ( $buffref, $eof ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 56 | ▶ | return 0 if $eof; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 50 | ▶ | return 0 unless $$buffref =~ s/^(.*?$CRLF$CRLF)//s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 26 | my $header = $1; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 26 | my $request = HTTP::Request->parse( $header ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 26 | ▶ | unless( $request and defined $request->protocol and $request->protocol =~ m/^HTTP/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$request and defined $request->protocol and $request->protocol =~ /^HTTP/u
$request and defined $request->protocol
MC/DC0%0/3
$request and defined $request->protocol and $request->protocol =~ /^HTTP/u
$request
defined $request->protocol
$request->protocol =~ /^HTTP/u
Truth table25%1/4
A and B and C
A= $requestB= defined $request->protocolC= $request->protocol =~ /^HTTP/u
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $self->close_now; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 26 | ▶ | my $request_body_len = $request->content_length || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$request->content_length || 0
MC/DC100%1/1
$request->content_length || 0
$request->content_length
Truth table100%2/2
A
A= $request->content_length
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 26 | $self->debug_printf( "REQUEST %s %s", $request->method, $request->uri->path ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 27 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 27 | my ( undef, $buffref, $eof ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 27 | ▶ | return 0 unless length($$buffref) >= $request_body_len; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 25 | $request->add_content( substr( $$buffref, 0, $request_body_len, "" ) ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 25 | push @{ $self->{requests} }, my $req = $self->parent->make_request( $self, $request ); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 25 | weaken( $self->{requests}[-1] ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 25 | $self->parent->_received_request( $req ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 25 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 26 | }; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | sub on_closed | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on_closed: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 8 | ▶ | $_ and $_->_close for @{ $self->{requests} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 8 | undef @{ $self->{requests} }; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | sub _flush_requests | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 61 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flush_requests: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 61 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 61 | my $queue = $self->{requests}; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 61 | ▶ | while( @$queue ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 62 | my $req = $queue->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 62 | ▶ | $req or shift @$queue, next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 62 | my $is_done = $req->_write_to_stream( $self ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 62 | ▶ | $is_done ? shift @$queue : return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 13 | 0x55AA; | |||||||||||||||||||||||||||||||||||||||||