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-2015 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Async::HTTP::Server::Protocol; |
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
86
|
use strict; |
|
12
|
|
|
|
|
29
|
|
|
12
|
|
|
|
|
383
|
|
9
|
12
|
|
|
12
|
|
58
|
use warnings; |
|
12
|
|
|
|
|
28
|
|
|
12
|
|
|
|
|
331
|
|
10
|
12
|
|
|
12
|
|
68
|
use base qw( IO::Async::Stream ); |
|
12
|
|
|
|
|
23
|
|
|
12
|
|
|
|
|
3530
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
13
|
|
|
|
|
|
|
|
14
|
12
|
|
|
12
|
|
97473
|
use Carp; |
|
12
|
|
|
|
|
30
|
|
|
12
|
|
|
|
|
753
|
|
15
|
12
|
|
|
12
|
|
85
|
use Scalar::Util qw( weaken ); |
|
12
|
|
|
|
|
28
|
|
|
12
|
|
|
|
|
653
|
|
16
|
|
|
|
|
|
|
|
17
|
12
|
|
|
12
|
|
6420
|
use HTTP::Request; |
|
12
|
|
|
|
|
179422
|
|
|
12
|
|
|
|
|
5519
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $CRLF = "\x0d\x0a"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub on_read |
22
|
|
|
|
|
|
|
{ |
23
|
54
|
|
|
54
|
1
|
53892
|
my $self = shift; |
24
|
54
|
|
|
|
|
136
|
my ( $buffref, $eof ) = @_; |
25
|
|
|
|
|
|
|
|
26
|
54
|
100
|
|
|
|
224
|
return 0 if $eof; |
27
|
|
|
|
|
|
|
|
28
|
48
|
100
|
|
|
|
606
|
return 0 unless $$buffref =~ s/^(.*?$CRLF$CRLF)//s; |
29
|
25
|
|
|
|
|
158
|
my $header = $1; |
30
|
|
|
|
|
|
|
|
31
|
25
|
|
|
|
|
206
|
my $request = HTTP::Request->parse( $header ); |
32
|
25
|
50
|
33
|
|
|
46787
|
unless( $request and defined $request->protocol and $request->protocol =~ m/^HTTP/ ) { |
|
|
|
33
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
$self->close_now; |
34
|
0
|
|
|
|
|
0
|
return 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
25
|
|
100
|
|
|
867
|
my $request_body_len = $request->content_length || 0; |
38
|
|
|
|
|
|
|
|
39
|
25
|
|
|
|
|
1481
|
$self->debug_printf( "REQUEST %s %s", $request->method, $request->uri->path ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return sub { |
42
|
26
|
|
|
26
|
|
1645
|
my ( undef, $buffref, $eof ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
26
|
100
|
|
|
|
109
|
return 0 unless length($$buffref) >= $request_body_len; |
45
|
|
|
|
|
|
|
|
46
|
24
|
|
|
|
|
189
|
$request->add_content( substr( $$buffref, 0, $request_body_len, "" ) ); |
47
|
|
|
|
|
|
|
|
48
|
24
|
|
|
|
|
504
|
push @{ $self->{requests} }, my $req = $self->parent->make_request( $self, $request ); |
|
24
|
|
|
|
|
124
|
|
49
|
24
|
|
|
|
|
152
|
weaken( $self->{requests}[-1] ); |
50
|
|
|
|
|
|
|
|
51
|
24
|
|
|
|
|
70
|
$self->parent->_received_request( $req ); |
52
|
|
|
|
|
|
|
|
53
|
24
|
|
|
|
|
293
|
return undef; |
54
|
25
|
|
|
|
|
1510
|
}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub on_closed |
58
|
|
|
|
|
|
|
{ |
59
|
8
|
|
|
8
|
1
|
16
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
8
|
|
33
|
|
|
16
|
$_ and $_->_close for @{ $self->{requests} }; |
|
8
|
|
|
|
|
32
|
|
62
|
8
|
|
|
|
|
14
|
undef @{ $self->{requests} }; |
|
8
|
|
|
|
|
23
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _flush_requests |
66
|
|
|
|
|
|
|
{ |
67
|
58
|
|
|
58
|
|
104
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
58
|
|
|
|
|
127
|
my $queue = $self->{requests}; |
70
|
58
|
|
|
|
|
155
|
while( @$queue ) { |
71
|
59
|
|
|
|
|
99
|
my $req = $queue->[0]; |
72
|
59
|
50
|
|
|
|
133
|
$req or shift @$queue, next; |
73
|
|
|
|
|
|
|
|
74
|
59
|
|
|
|
|
154
|
my $is_done = $req->_write_to_stream( $self ); |
75
|
|
|
|
|
|
|
|
76
|
59
|
100
|
|
|
|
403
|
$is_done ? shift @$queue : return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
0x55AA; |