blib/lib/Plack/HTTPParser/PP.pm

filter: Statementstmt 96.4% 54 / 56 Branchbran 65.0% 13 / 20 Conditioncond 60.0% 6 / 10 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 81.6% 80 / 98 CC 18 SCAR 24.5
CC
18
Cov
85%
_parse_header
15.7
parse_http_request
4.5
BEGIN
1.0
CRAP 11.6
« blib/lib/Plack/Middleware/XSendfile.pm ↑ Summary blib/lib/Plack/App/WrapCGI.pm »
1 package Plack::HTTPParser::PP;
2 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 42 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 735 ▶sub parse_http_request {
Subroutine parse_http_request: called CC=4 SCAR=15.0
Pod undocumented
7 735 my($chunk, $env) = @_;
8 735 ▶ $env ||= {};
Condition50%1/2
$env ||= {}
l!l
7350
MC/DC0%0/1
$env ||= {}
$env
Truth table50%1/2
A
A= $env
Aresult
11
00
9  
10 # pre-header blank lines are allowed (RFC 2616 4.1)
11 735 $chunk =~ s/^(\x0d?\x0a)+//;
12 735 ▶ return -2 unless length $chunk;
Branch: 1 branch
BranchTrueFalseTotal
unless length $chunk 0 735 735
13  
14 # double line break indicates end of header; parse it
15 735 ▶ if ($chunk =~ /^(.*?\x0d?\x0a\x0d?\x0a)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk =~ /^(.*?\x0d?\x0a\x0d?\x0a)/s) 735 0 735
16 735 return _parse_header($chunk, length $1, $env);
17 }
18 0 return -2; # still waiting for unknown amount of header lines
19 }
20  
21 735 ▶sub _parse_header {
Subroutine _parse_header: called CC=15 SCAR=27.5
22 735 my($chunk, $eoh, $env) = @_;
23  
24 735 my $header = substr($chunk, 0, $eoh,'');
25 735 $chunk =~ s/^\x0d?\x0a\x0d?\x0a//;
26  
27 # parse into lines
28 735 my @header = split /\x0d?\x0a/,$header;
29 735 my $request = shift @header;
30  
31 # join folded lines
32 735 my @out;
33 735 for(@header) {
34 2480 ▶ if(/^[ \t]+/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[ \t]+/) { } 2 2478 2480
35 2 ▶ return -1 unless @out;
Branch: 1 branch
BranchTrueFalseTotal
unless @out 0 2 2
36 2 $out[-1] .= $_;
37 } else {
38 2478 push @out, $_;
39 }
40 }
41  
42 # parse request or response line
43 735 my $obj;
44 735 my ($major, $minor);
45  
46 735 my ($method,$uri,$http) = split / /,$request;
47 735 ▶ return -1 unless $http and $http =~ /^HTTP\/(\d+)\.(\d+)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $http and $http =~ m[^HTTP/(\d+)\.(\d+)$]i 0 735 735
Condition33%1/3
$http and $http =~ m[^HTTP/(\d+)\.(\d+)$]i
!ll&&!rl&&r
00735
MC/DC0%0/2
$http and $http =~ m[^HTTP/(\d+)\.(\d+)$]i
$http $http =~ m[^HTTP/(\d+)\.(\d+)$]i
Truth table33%1/3
A and B
A= $httpB= $http =~ m[^HTTP/(\d+)\.(\d+)$]i
ABresult
0X0
100
111
48 735 ($major, $minor) = ($1, $2);
49  
50 735 $env->{REQUEST_METHOD} = $method;
51 735 $env->{SERVER_PROTOCOL} = "HTTP/$major.$minor";
52 735 $env->{REQUEST_URI} = $uri;
53  
54 735 my($path, $query) = ( $uri =~ /^([^?]*)(?:\?(.*))?$/s );
55 735 ▶ for ($path, $query) { s/\#.*$// if defined && length } # dumb clients sending URI fragments
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ and length $_ 953 517 1470
Condition66%2/3
defined $_ and length $_
!ll&&!rl&&r
5170953
MC/DC50%1/2
defined $_ and length $_
defined $_ length $_
Truth table66%2/3
A and B
A= defined $_B= length $_
ABresult
0X0
100
111
56  
57 735 $env->{PATH_INFO} = URI::Escape::uri_unescape($path);
58 735 ▶ $env->{QUERY_STRING} = $query || '';
Condition100%2/2
$query || ''
l!l
218517
MC/DC100%1/1
$query || ''
$query
Truth table100%2/2
A
A= $query
Aresult
11
00
59 735 $env->{SCRIPT_NAME} = '';
60  
61 # import headers
62 735 my $token = qr/[^][\x00-\x1f\x7f()<>@,;:\\"\/?={} \t]+/;
63 735 my $k;
64 735 for my $header (@out) {
65 2478 ▶ if ( $header =~ s/^($token): ?// ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($header =~ s/^($token): ?//) { } 2478 0 2478
elsif ($header =~ /^\s+/) { } 0 0 0
66 2478 $k = $1;
67 2478 $k =~ s/-/_/g;
68 2478 $k = uc $k;
69  
70 2478 ▶ if ($k !~ /^(?:CONTENT_LENGTH|CONTENT_TYPE)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($k =~ /^(?:CONTENT_LENGTH|CONTENT_TYPE)$/) 2240 238 2478
71 2240 $k = "HTTP_$k";
72 }
73 } elsif ( $header =~ /^\s+/) {
74 # multiline header
75 } else {
76 0 return -1;
77 }
78  
79 2478 ▶ if (exists $env->{$k}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $env->{$k}) { } 20 2458 2478
80 20 $env->{$k} .= ", $header";
81 } else {
82 2458 $env->{$k} = $header;
83 }
84 }
85  
86 735 return $eoh;
87 }
88  
89 42 1;
90  
91 __END__
« blib/lib/Plack/Middleware/XSendfile.pm ↑ Summary blib/lib/Plack/App/WrapCGI.pm »