line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::StreamParser::Request; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$HTTP::StreamParser::Request::VERSION = '0.101'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
1192
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
7
|
1
|
|
|
1
|
|
711
|
use parent qw(HTTP::StreamParser); |
|
1
|
|
|
|
|
285
|
|
|
1
|
|
|
|
|
5
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
HTTP::StreamParser::Request - streaming parser for HTTP response data |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
version 0.101 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
49
|
use List::Util qw(min); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
306
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 state_sequence |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Returns the sequence of states this request can be in, as a list. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub state_sequence { |
36
|
1
|
|
|
1
|
1
|
16
|
qw( |
37
|
|
|
|
|
|
|
http_method single_space http_uri single_space http_version newline |
38
|
|
|
|
|
|
|
http_headers |
39
|
|
|
|
|
|
|
http_body |
40
|
|
|
|
|
|
|
) |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 request_method |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Parse the request method. Expects a single word. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub request_method { |
50
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
my $buf = shift; |
52
|
0
|
0
|
|
|
|
|
if($$buf =~ s/^([A-Z]+)(?=\s)//) { |
53
|
0
|
|
|
|
|
|
$self->{method} = $1; |
54
|
0
|
0
|
|
|
|
|
die "invalid method ". $self->{method} unless $self->validate_method($self->{method}); |
55
|
0
|
|
|
|
|
|
$self->invoke_event(request_method => $self->{method}); |
56
|
0
|
|
|
|
|
|
$self->parse_state('request_uri'); |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
return $self |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 request_uri |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Parse the URI. May be an empty string. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub request_uri { |
68
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
69
|
0
|
|
|
|
|
|
my $buf = shift; |
70
|
0
|
0
|
|
|
|
|
if($$buf =~ s/^([^ ]*)(?=\s)//) { |
71
|
0
|
|
|
|
|
|
$self->{uri} = $1; |
72
|
0
|
|
|
|
|
|
$self->invoke_event(request_uri => $self->{uri}); |
73
|
0
|
|
|
|
|
|
$self->parse_state('request_version'); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
return $self |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 request_version |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Parse the HTTP version stanza. Probably HTTP/1.1. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub request_version { |
85
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
86
|
0
|
|
|
|
|
|
my $buf = shift; |
87
|
0
|
0
|
|
|
|
|
if($$buf =~ s{^(HTTP)/(\d+.\d+)(?=\s)}{}) { |
88
|
0
|
|
|
|
|
|
$self->{proto} = $1; |
89
|
0
|
|
|
|
|
|
$self->{version} = $2; |
90
|
0
|
|
|
|
|
|
$self->invoke_event(request_version => $self->{proto}, $self->{version}); |
91
|
0
|
|
|
|
|
|
$self->parse_state('request_headers'); |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
return $self |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Tom Molesworth <cpan@entitymodel.com> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 LICENSE |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Copyright Tom Molesworth 2013. Licensed under the same terms as Perl itself. |