| 1 | package Limper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | $Limper::VERSION = '0.014'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.10.0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Exporter qw/import/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | our @EXPORT = qw/get post put del trace options patch any status headers request response config hook limp/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our @EXPORT_OK = qw/info warning rfc1123date/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # data stored here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | my $request = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | my $response = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | my $config = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my $hook = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my $conn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # route subs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | my $route = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub get { push @{$route->{GET}}, @_; @_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub post { push @{$route->{POST}}, @_; @_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub put { push @{$route->{PUT}}, @_; @_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
put: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub del { push @{$route->{DELETE}}, @_; @_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
del: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub trace { push @{$route->{TRACE}}, @_; @_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub options { push @{$route->{OPTIONS}}, @_; @_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub patch { push @{$route->{PATCH}}, @_; @_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
patch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub any { push @{$route->{$_}}, @_ for keys %$route } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
any: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub routes { $_[0] ? $route->{uc $_[0]} : $route } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
routes: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # for send_response() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | my $reasons = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 100 => 'Continue', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 101 => 'Switching Protocols', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 200 => 'OK', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 201 => 'Created', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 202 => 'Accepted', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 203 => 'Non-Authoritative Information', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 204 => 'No Content', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 205 => 'Reset Content', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 206 => 'Partial Content', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 300 => 'Multiple Choices', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 301 => 'Moved Permanently', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 302 => 'Found', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 303 => 'See Other', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 304 => 'Not Modified', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 305 => 'Use Proxy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 307 => 'Temporary Redirect', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 400 => 'Bad Request', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 401 => 'Unauthorized', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 402 => 'Payment Required', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 403 => 'Forbidden', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 404 => 'Not Found', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 405 => 'Method Not Allowed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 406 => 'Not Acceptable', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 407 => 'Proxy Authentication Required', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 408 => 'Request Time-out', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 409 => 'Conflict', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 410 => 'Gone', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 411 => 'Length Required', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 412 => 'Precondition Failed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 413 => 'Request Entity Too Large', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 414 => 'Request-URI Too Large', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 415 => 'Unsupported Media Type', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 416 => 'Requested range not satisfiable', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 417 => 'Expectation Failed', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 500 => 'Internal Server Error', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 501 => 'Not Implemented', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 502 => 'Bad Gateway', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 503 => 'Service Unavailable', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 504 => 'Gateway Time-out', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 505 => 'HTTP Version not supported', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # for get_request() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | my $method_rx = qr/(?: OPTIONS | GET | HEAD | POST | PUT | DELETE | TRACE | CONNECT )/x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | my $version_rx = qr{HTTP/\d+\.\d+}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | my $uri_rx = qr/[^ ]+/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # Returns current time or passed timestamp as an HTTP 1.1 date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | my @months = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | my @days = qw/Sun Mon Tue Wed Thu Fri Sat/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | sub rfc1123date { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my ($sec, $min, $hour, $mday, $mon, $year, $wday) = @_ ? gmtime $_[0] : gmtime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rfc1123date: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | sprintf '%s, %02d %s %4d %02d:%02d:%02d GMT', $days[$wday], $mday, $months[$mon], $year + 1900, $hour, $min, $sec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Formats date like "2014-08-17 00:12:41" in local time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | sub date { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my ($sec, $min, $hour, $mday, $mon, $year) = localtime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | sprintf '%04d-%02d-%02d %02d:%02d:%02d', $year + 1900, $mon, $mday, $hour, $min, $sec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # Trivially log to STDOUT or STDERR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub info { say date, ' ', @_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub warning { warn date, ' ', @_ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warning: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | sub timeout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
timeout: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | local $SIG{ALRM} = sub { die "alarm\n" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | alarm($config->{timeout} // 5); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"timeout"} // 5
MC/DC0%0/1
$config->{"timeout"} // 5
$config->{"timeout"}
Truth table0%0/2
A
A= $config->{"timeout"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $_ = $_[0]->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | alarm 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $@ ? ($conn->close and undef) : $_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$conn->close and undef
MC/DC0%0/1
$conn->close and undef
$conn->close
Truth table0%0/2
A
A= $conn->close
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | sub bad_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | warning "[$request->{remote_host}] bad request: $_[0]"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bad_request: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $response = { status => 400, body => 'Bad Request' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | send_response($request->{method} // '' eq 'HEAD', 'close'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$request->{"method"} //
MC/DC0%0/1
$request->{"method"} //
$request->{"method"}
Truth table0%0/2
A
A= $request->{"method"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Returns a processed request as a hash, or sends a 400 and closes if invalid. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | sub get_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $request = { headers => {}, remote_host => $conn->peerhost // 'localhost' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_request: not called CC=30 SCAR=68.4
Pod
undocumented
Condition0%0/2
$conn->peerhost // "localhost"
MC/DC0%0/1
$conn->peerhost // "localhost"
$conn->peerhost
Truth table0%0/2
A
A= $conn->peerhost
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $response = { headers => {} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my ($request_line, $headers_done, $chunked); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | defined(my $line = timeout(sub { $conn->getline })) or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if (!defined $request_line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | next if $line eq "\r\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ($request->{method}, $request->{uri}, $request->{version}) = $line =~ /^($method_rx) ($uri_rx) ($version_rx)\r\n/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | return bad_request $line unless defined $request->{method}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ($request->{scheme}, $request->{authority}, $request->{path}, $request->{query}, $request->{fragment}) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $request->{uri} =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|; # from https://metacpan.org/pod/URI | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $request_line = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } elsif (!defined $headers_done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if ($line =~ /^\r\n/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $headers_done = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my ($name, $value) = split /:[ \t]*/, $line, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ($name =~ /\r\n/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | return bad_request $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $value =~ s/\r\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $value = $1 if lc $name eq 'host' and $request->{version} eq 'HTTP/1.1' and $request->{uri} =~ s{^https?://(.+?)/}{/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
lc $name eq "host" and $request->{"version"} eq "HTTP/1.1" and $request->{"uri"} =~ s[^https?://(.+?)/][/]
lc $name eq "host" and $request->{"version"} eq "HTTP/1.1"
MC/DC0%0/3
lc $name eq "host" and $request->{"version"} eq "HTTP/1.1" and $request->{"uri"} =~ s[^https?://(.+?)/][/]
lc $name eq "host"
$request->{"version"} eq "HTTP/1.1"
$request->{"uri"} =~ s[^https?://(.+?)/][/]
Truth table0%0/4
A and B and C
A= lc $name eq "host"B= $request->{"version"} eq "HTTP/1.1"C= $request->{"uri"} =~ s[^https?://(.+?)/][/]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if (exists $request->{headers}{lc $name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if (ref $request->{headers}{lc $name}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | push @{$request->{headers}{lc $name}}, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $request->{headers}{lc $name} = [$request->{headers}{lc $name}, $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $request->{headers}{lc $name} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (defined $headers_done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return if defined $chunked; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | info "[$request->{remote_host}] $request->{method} $request->{uri} $request->{version} [", $request->{headers}{'user-agent'} // '', ']'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$request->{"headers"}{"user-agent"} // ""
MC/DC0%0/1
$request->{"headers"}{"user-agent"} // ""
$request->{"headers"}{"user-agent"}
Truth table0%0/2
A
A= $request->{"headers"}{"user-agent"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | return bad_request 'Host header missing' if $request->{version} eq 'HTTP/1.1' and (!exists $request->{headers}{host} or ref $request->{headers}{host}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$request->{"version"} eq "HTTP/1.1" and !exists $request->{"headers"}{"host"} || ref $request->{"headers"}{"host"}
not exists $request->{"headers"}{"host"} or ref $request->{"headers"}{"host"}
MC/DC0%0/3
$request->{"version"} eq "HTTP/1.1" and !exists $request->{"headers"}{"host"} || ref $request->{"headers"}{"host"}
$request->{"version"} eq "HTTP/1.1"
not exists $request->{"headers"}{"host"}
ref $request->{"headers"}{"host"}
Truth table0%0/4
A and not(B) or C
A= $request->{"version"} eq "HTTP/1.1"B= not exists $request->{"headers"}{"host"}C= ref $request->{"headers"}{"host"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | for (keys %{$request->{headers}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ($_ eq 'expect' and lc $request->{headers}{$_} eq '100-continue' and $request->{version} eq 'HTTP/1.1') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/6
$_ eq "expect" and lc $request->{"headers"}{$_} eq "100-continue" and $request->{"version"} eq "HTTP/1.1"
$_ eq "expect" and lc $request->{"headers"}{$_} eq "100-continue"
MC/DC0%0/3
$_ eq "expect" and lc $request->{"headers"}{$_} eq "100-continue" and $request->{"version"} eq "HTTP/1.1"
$_ eq "expect"
lc $request->{"headers"}{$_} eq "100-continue"
$request->{"version"} eq "HTTP/1.1"
Truth table0%0/4
A and B and C
A= $_ eq "expect"B= lc $request->{"headers"}{$_} eq "100-continue"C= $request->{"version"} eq "HTTP/1.1"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $conn->print("HTTP/1.1 100 Continue\r\n\r\n"); # this does not check if route is valid. just here to comply. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } elsif ($_ eq 'content-length') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | timeout(sub { $conn->read($request->{body}, $request->{headers}{$_}) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ▶ | } elsif ($_ eq 'transfer-encoding' and lc $request->{headers}{$_} eq 'chunked') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_ eq "transfer-encoding" and lc $request->{"headers"}{$_} eq "chunked"
MC/DC0%0/2
$_ eq "transfer-encoding" and lc $request->{"headers"}{$_} eq "chunked"
$_ eq "transfer-encoding"
lc $request->{"headers"}{$_} eq "chunked"
Truth table0%0/3
A and B
A= $_ eq "transfer-encoding"B= lc $request->{"headers"}{$_} eq "chunked"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $length = my $offset = $chunked = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | $_ = timeout(sub { $conn->getline }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $length = hex((/^([A-Fa-f0-9]+)(?:;.*)?\r\n/)[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | timeout(sub { $conn->read($request->{body}, $length + 2, $offset) }) if $length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $offset += $length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } while $length; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $request->{body} =~ s/\r\n$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | undef $headers_done; # to get optional footers, and another blank line | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | last if defined $headers_done; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # Finds and calls the appropriate route sub, or sends a 404 response. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | sub handle_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | my $head = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_request: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | (defined $request->{method} and $request->{method} eq 'HEAD') ? ($request->{method} = 'GET') : ($head = 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $request->{"method"} and $request->{"method"} eq "HEAD"
MC/DC0%0/2
defined $request->{"method"} and $request->{"method"} eq "HEAD"
defined $request->{"method"}
$request->{"method"} eq "HEAD"
Truth table0%0/3
A and B
A= defined $request->{"method"}B= $request->{"method"} eq "HEAD"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if (defined $request->{method} and exists $route->{$request->{method}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $request->{"method"} and exists $$route{$request->{"method"}}
MC/DC0%0/2
defined $request->{"method"} and exists $$route{$request->{"method"}}
defined $request->{"method"}
exists $$route{$request->{"method"}}
Truth table0%0/3
A and B
A= defined $request->{"method"}B= exists $$route{$request->{"method"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | for (my $i = 0; $i < @{$route->{$request->{method}}}; $i += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ($route->{$request->{method}}[$i] eq $request->{path} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$$route{$request->{"method"}}[$i] eq $request->{"path"} || ref $$route{$request->{"method"}}[$i] eq "Regexp" and $request->{"path"} =~ /$$route{$request->{"method"}}[$i]/
$$route{$request->{"method"}}[$i] eq $request->{"path"} or ref $$route{$request->{"method"}}[$i] eq "Regexp"
MC/DC0%0/3
$$route{$request->{"method"}}[$i] eq $request->{"path"} || ref $$route{$request->{"method"}}[$i] eq "Regexp" and $request->{"path"} =~ /$$route{$request->{"method"}}[$i]/
$$route{$request->{"method"}}[$i] eq $request->{"path"}
ref $$route{$request->{"method"}}[$i] eq "Regexp"
$request->{"path"} =~ /$$route{$request->{"method"}}[$i]/
Truth table0%0/5
A or B and C
A= $$route{$request->{"method"}}[$i] eq $request->{"path"}B= ref $$route{$request->{"method"}}[$i] eq "Regexp"C= $request->{"path"} =~ /$$route{$request->{"method"}}[$i]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ref $route->{$request->{method}}[$i] eq 'Regexp' and $request->{path} =~ $route->{$request->{method}}[$i]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $response->{body} = & { $route->{$request->{method}}[$i+1] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return send_response($head); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $response->{body} = 'This is the void'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $response->{status} = 404; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | send_response($head); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # Sends a response to client. Default status is 200. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | sub send_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | my ($head, $connection) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_response: not called CC=27 SCAR=66.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | $connection //= (($request->{version} // '') eq 'HTTP/1.1') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ? lc($request->{headers}{connection} // '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | : lc($request->{headers}{connection} // 'close') eq 'keep-alive' ? 'keep-alive' : 'close'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/9
$connection //= ($request->{"version"} // "") eq "HTTP/1.1" ? lc($request->{"headers"}{"connection"} // "") : (lc($request->{"headers"}{"connection"} // "close") eq "keep-alive" ? "keep-alive" : "close")
$request->{"version"} // ""
$request->{"headers"}{"connection"} // ""
$request->{"headers"}{"connection"} // "close"
MC/DC0%0/2
$connection //= ($request->{"version"} // "") eq "HTTP/1.1" ? lc($request->{"headers"}{"connection"} // "") : (lc($request->{"headers"}{"connection"} // "close") eq "keep-alive" ? "keep-alive" : "close")
$connection
$request->{"version"}
MC/DC0%0/1
$request->{"headers"}{"connection"} // ""
$request->{"headers"}{"connection"}
MC/DC0%0/1
$request->{"headers"}{"connection"} // "close"
$request->{"headers"}{"connection"}
Truth table0%0/3
A //= B
A= $connectionB= $request->{"version"}
Truth table0%0/2
A
A= $request->{"headers"}{"connection"}
Truth table0%0/2
A
A= $request->{"headers"}{"connection"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $response->{status} //= 200; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$response->{"status"} //= 200
MC/DC0%0/1
$response->{"status"} //= 200
$response->{"status"}
Truth table0%0/2
A
A= $response->{"status"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $response->{headers}{Date} = rfc1123date(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if (defined $response->{body} and !ref $response->{body}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $response->{"body"} and not ref $response->{"body"}
MC/DC0%0/2
defined $response->{"body"} and not ref $response->{"body"}
defined $response->{"body"}
not ref $response->{"body"}
Truth table0%0/3
A and not(B)
A= defined $response->{"body"}B= not ref $response->{"body"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | $response->{headers}{'Content-Length'} //= length $response->{body}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$response->{"headers"}{"Content-Length"} //= length $response->{"body"}
MC/DC0%0/2
$response->{"headers"}{"Content-Length"} //= length $response->{"body"}
$response->{"headers"}{"Content-Length"}
length $response->{"body"}
Truth table0%0/3
A //= B
A= $response->{"headers"}{"Content-Length"}B= length $response->{"body"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | $response->{headers}{'Content-Type'} //= 'text/plain'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$response->{"headers"}{"Content-Type"} //= "text/plain"
MC/DC0%0/1
$response->{"headers"}{"Content-Type"} //= "text/plain"
$response->{"headers"}{"Content-Type"}
Truth table0%0/2
A
A= $response->{"headers"}{"Content-Type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | delete $response->{body} if $head // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$head // 0
MC/DC0%0/1
$head // 0
$head
Truth table0%0/2
A
A= $head
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | $response->{headers}{Connection} = $connection if $connection eq 'close' or ($connection eq 'keep-alive' and $request->{version} ne 'HTTP/1.1'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$connection eq "close" or $connection eq "keep-alive" and $request->{"version"} ne "HTTP/1.1"
$connection eq "keep-alive" and $request->{"version"} ne "HTTP/1.1"
MC/DC0%0/3
$connection eq "close" or $connection eq "keep-alive" and $request->{"version"} ne "HTTP/1.1"
$connection eq "close"
$connection eq "keep-alive"
$request->{"version"} ne "HTTP/1.1"
Truth table0%0/4
A or B and C
A= $connection eq "close"B= $connection eq "keep-alive"C= $request->{"version"} ne "HTTP/1.1"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | $response->{headers}{Server} = 'limper/' . ($Limper::VERSION // 'pre-release'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$Limper::VERSION // "pre-release"
MC/DC0%0/1
$Limper::VERSION // "pre-release"
$Limper::VERSION
Truth table0%0/2
A
A= $Limper::VERSION
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $_->($request, $response) for @{$hook->{after}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | return $hook->{response_handler}[0]->() if exists $hook->{response_handler}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | local $\ = "\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | $conn->print(join ' ', $request->{version} // 'HTTP/1.1', $response->{status}, $response->{reason} // $reasons->{$response->{status}}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$request->{"version"} // "HTTP/1.1"
$response->{"reason"} // $$reasons{$response->{"status"}}
MC/DC0%0/1
$request->{"version"} // "HTTP/1.1"
$request->{"version"}
MC/DC0%0/2
$response->{"reason"} // $$reasons{$response->{"status"}}
$response->{"reason"}
$$reasons{$response->{"status"}}
Truth table0%0/2
A
A= $request->{"version"}
Truth table0%0/3
A // B
A= $response->{"reason"}B= $$reasons{$response->{"status"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | return unless $conn->connected; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my @headers = headers(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $conn->print( join(': ', splice(@headers, 0, 2)) ) while @headers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $conn->print(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $conn->print($response->{body} // '') if defined $response->{body}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$response->{"body"} // ""
MC/DC0%0/1
$response->{"body"} // ""
$response->{"body"}
Truth table0%0/2
A
A= $response->{"body"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | $conn->close if $connection eq 'close'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | sub status { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if (defined wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: not called CC=4 SCAR=30.0
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | wantarray ? ($response->{status}, $response->{reason}) : $response->{status}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $response->{status} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | $response->{reason} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | sub headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if (!defined wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headers: not called CC=6 SCAR=37.4
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $response->{headers}{+pop} = pop while @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my @headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | for my $key (keys %{ $response->{headers} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if (ref $response->{headers}{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | push @headers, $key, $_ for @{$response->{headers}{$key}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | push @headers, $key, $response->{headers}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | @headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | sub request { $request } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub response { $response } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
response: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | sub config { $config } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | sub hook { push @{$hook->{$_[0]}}, $_[1] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hook: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | sub limp { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | $config = shift @_ if ref $_[0] eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
limp: not called CC=17 SCAR=57.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | return $hook->{request_handler}[0] if exists $hook->{request_handler}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | my $sock = IO::Socket::INET->new(Listen => SOMAXCONN, ReuseAddr => 1, LocalAddr => 'localhost', LocalPort => 8080, Proto => 'tcp', @_) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | or die "cannot bind to port: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | info 'limper started'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | for (1 .. $config->{workers} // 5) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"workers"} // 5
MC/DC0%0/1
$config->{"workers"} // 5
$config->{"workers"}
Truth table0%0/2
A
A= $config->{"workers"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | defined(my $pid = fork) or die "fork failed: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | while (!$pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if ($conn = $sock->accept()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | get_request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | handle_request if $conn->connected; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | $response = { status => 500, body => $config->{debug} // 0 ? $@ : 'Internal Server Error' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$config->{"debug"} // 0
MC/DC0%0/1
$config->{"debug"} // 0
$config->{"debug"}
Truth table0%0/2
A
A= $config->{"debug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | send_response 0, 'close'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | warning $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } while ($conn->connected); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | 1 while (wait != -1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $shutdown = $sock->shutdown(2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | my $closed = $sock->close(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | info 'shutdown ', $shutdown ? 'successful' : 'unsuccessful'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | info 'closed ', $closed ? 'successful' : 'unsuccessful'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||