line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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.14; |
7
|
|
|
|
|
|
|
|
8
|
13
|
|
|
13
|
|
164
|
use v5.14; |
|
13
|
|
|
|
|
45
|
|
9
|
13
|
|
|
13
|
|
72
|
use warnings; |
|
13
|
|
|
|
|
49
|
|
|
13
|
|
|
|
|
460
|
|
10
|
13
|
|
|
13
|
|
90
|
use base qw( IO::Async::Stream ); |
|
13
|
|
|
|
|
57
|
|
|
13
|
|
|
|
|
4125
|
|
11
|
|
|
|
|
|
|
|
12
|
13
|
|
|
13
|
|
50641
|
use Carp; |
|
13
|
|
|
|
|
36
|
|
|
13
|
|
|
|
|
790
|
|
13
|
13
|
|
|
13
|
|
91
|
use Scalar::Util qw( weaken ); |
|
13
|
|
|
|
|
33
|
|
|
13
|
|
|
|
|
636
|
|
14
|
|
|
|
|
|
|
|
15
|
13
|
|
|
13
|
|
6396
|
use HTTP::Request; |
|
13
|
|
|
|
|
232641
|
|
|
13
|
|
|
|
|
5903
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $CRLF = "\x0d\x0a"; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub on_read |
20
|
|
|
|
|
|
|
{ |
21
|
56
|
|
|
56
|
1
|
56237
|
my $self = shift; |
22
|
56
|
|
|
|
|
133
|
my ( $buffref, $eof ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
56
|
100
|
|
|
|
166
|
return 0 if $eof; |
25
|
|
|
|
|
|
|
|
26
|
50
|
100
|
|
|
|
584
|
return 0 unless $$buffref =~ s/^(.*?$CRLF$CRLF)//s; |
27
|
26
|
|
|
|
|
113
|
my $header = $1; |
28
|
|
|
|
|
|
|
|
29
|
26
|
|
|
|
|
221
|
my $request = HTTP::Request->parse( $header ); |
30
|
26
|
50
|
33
|
|
|
50325
|
unless( $request and defined $request->protocol and $request->protocol =~ m/^HTTP/ ) { |
|
|
|
33
|
|
|
|
|
31
|
0
|
|
|
|
|
0
|
$self->close_now; |
32
|
0
|
|
|
|
|
0
|
return 0; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
26
|
|
100
|
|
|
862
|
my $request_body_len = $request->content_length || 0; |
36
|
|
|
|
|
|
|
|
37
|
26
|
|
|
|
|
1899
|
$self->debug_printf( "REQUEST %s %s", $request->method, $request->uri->path ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return sub { |
40
|
27
|
|
|
27
|
|
1673
|
my ( undef, $buffref, $eof ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
27
|
100
|
|
|
|
101
|
return 0 unless length($$buffref) >= $request_body_len; |
43
|
|
|
|
|
|
|
|
44
|
25
|
|
|
|
|
199
|
$request->add_content( substr( $$buffref, 0, $request_body_len, "" ) ); |
45
|
|
|
|
|
|
|
|
46
|
25
|
|
|
|
|
468
|
push @{ $self->{requests} }, my $req = $self->parent->make_request( $self, $request ); |
|
25
|
|
|
|
|
126
|
|
47
|
25
|
|
|
|
|
131
|
weaken( $self->{requests}[-1] ); |
48
|
|
|
|
|
|
|
|
49
|
25
|
|
|
|
|
74
|
$self->parent->_received_request( $req ); |
50
|
|
|
|
|
|
|
|
51
|
25
|
|
|
|
|
279
|
return undef; |
52
|
26
|
|
|
|
|
1594
|
}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub on_closed |
56
|
|
|
|
|
|
|
{ |
57
|
8
|
|
|
8
|
1
|
17
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
8
|
|
33
|
|
|
22
|
$_ and $_->_close for @{ $self->{requests} }; |
|
8
|
|
|
|
|
36
|
|
60
|
8
|
|
|
|
|
18
|
undef @{ $self->{requests} }; |
|
8
|
|
|
|
|
22
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _flush_requests |
64
|
|
|
|
|
|
|
{ |
65
|
61
|
|
|
61
|
|
104
|
my $self = shift; |
66
|
|
|
|
|
|
|
|
67
|
61
|
|
|
|
|
105
|
my $queue = $self->{requests}; |
68
|
61
|
|
|
|
|
158
|
while( @$queue ) { |
69
|
62
|
|
|
|
|
130
|
my $req = $queue->[0]; |
70
|
62
|
50
|
|
|
|
152
|
$req or shift @$queue, next; |
71
|
|
|
|
|
|
|
|
72
|
62
|
|
|
|
|
156
|
my $is_done = $req->_write_to_stream( $self ); |
73
|
|
|
|
|
|
|
|
74
|
62
|
100
|
|
|
|
401
|
$is_done ? shift @$queue : return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
0x55AA; |