| 1 | package HTTP::Daemon; # git description: v6.05-4-g31c6eaf | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: A simple http server class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '6.06'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | use Socket qw( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | AF_INET AF_INET6 INADDR_ANY IN6ADDR_ANY INADDR_LOOPBACK IN6ADDR_LOOPBACK | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | inet_ntop sockaddr_family | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use IO::Socket::IP; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | our @ISA = qw(IO::Socket::IP); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | our $PROTO = "HTTP/1.1"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | our $DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | $args{Listen} ||= 5; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"Listen"} ||= 5
MC/DC0%0/1
$args{"Listen"} ||= 5
$args{"Listen"}
Truth table50%1/2
A
A= $args{"Listen"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | $args{Proto} ||= 'tcp'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"Proto"} ||= "tcp"
MC/DC0%0/1
$args{"Proto"} ||= "tcp"
$args{"Proto"}
Truth table50%1/2
A
A= $args{"Proto"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Handle undefined or empty local address the same way as | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # IO::Socket::INET -- use unspecified address | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | for my $key (qw(LocalAddr LocalHost)) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | if (exists $args{$key} && (!defined $args{$key} || $args{$key} eq '')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
exists $args{$key} and !defined($args{$key}) || $args{$key} eq ""
not defined $args{$key} or $args{$key} eq ""
MC/DC0%0/3
exists $args{$key} and !defined($args{$key}) || $args{$key} eq ""
exists $args{$key}
not defined $args{$key}
$args{$key} eq ""
Truth table50%2/4
A and not(B) or C
A= exists $args{$key}B= not defined $args{$key}C= $args{$key} eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | delete $args{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | return $class->SUPER::new(%args); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | sub accept { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | my $pkg = shift || "HTTP::Daemon::ClientConn"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 'HTTP::Daemon::ClientConn'
MC/DC0%0/1
shift() || 'HTTP::Daemon::ClientConn'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | my ($sock, $peer) = $self->SUPER::accept($pkg); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | ▶ | if ($sock) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 5 | ${*$sock}{'httpd_daemon'} = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | ▶ | return wantarray ? ($sock, $peer) : $sock; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | sub url { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
url: called CC=15 SCAR=47.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 5 | my $url = $self->_default_scheme . "://"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | my $addr = $self->sockaddr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | ▶ | if (!$addr || $addr eq INADDR_ANY || $addr eq IN6ADDR_ANY) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%2/6
not $addr or $addr eq "\0\0\0\0" or $addr eq "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
not $addr or $addr eq "\0\0\0\0"
MC/DC0%0/3
not $addr or $addr eq "\0\0\0\0" or $addr eq "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
not $addr
$addr eq "\0\0\0\0"
$addr eq "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
Truth table25%1/4
not(A) or B or C
A= not $addrB= $addr eq "\0\0\0\0"C= $addr eq "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 5 | require Sys::Hostname; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | $url .= lc Sys::Hostname::hostname(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | elsif ($addr eq INADDR_LOOPBACK) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $url .= inet_ntop(AF_INET, $addr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | elsif ($addr eq IN6ADDR_LOOPBACK) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $url .= '[' . inet_ntop(AF_INET6, $addr) . ']'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $host = $self->sockhostname; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # sockhostname() seems to return a stringified IP address if not | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # resolvable. Then quote it for a port separator and an IPv6 zone | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # separator. But be paranoid for a case when it already contains | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # a bracket. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if (defined $host and $host =~ /:/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $host and $host =~ /:/
MC/DC0%0/2
defined $host and $host =~ /:/
defined $host
$host =~ /:/
Truth table0%0/3
A and B
A= defined $hostB= $host =~ /:/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ($host =~ /[\[\]]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $host = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $host =~ s/%/%25/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $host = '[' . $host . ']'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if (!defined $host) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $family = sockaddr_family($self->sockname); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ($family && $family == AF_INET6) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$family and $family == 10
MC/DC0%0/2
$family and $family == 10
$family
$family == 10
Truth table0%0/3
A and B
A= $familyB= $family == 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $host = '[' . inet_ntop(AF_INET6, $addr) . ']'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ▶ | elsif ($family && $family == AF_INET) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$family and $family == 2
MC/DC0%0/2
$family and $family == 2
$family
$family == 2
Truth table0%0/3
A and B
A= $familyB= $family == 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $host = inet_ntop(AF_INET, $addr); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | die "Unknown family"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $url .= $host; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 5 | my $port = $self->sockport; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 5 | ▶ | $url .= ":$port" if $port != $self->_default_port; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 5 | $url .= "/"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 5 | $url; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | sub _default_port { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 5 | ▶ | 80; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_port: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | sub _default_scheme { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | ▶ | "http"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_scheme: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | sub product_tokens { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | ▶ | "libwww-perl-daemon/$HTTP::Daemon::VERSION"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
product_tokens: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | package # hide from PAUSE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | HTTP::Daemon::ClientConn; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | ▶ | use IO::Socket::IP (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | our @ISA = qw(IO::Socket::IP); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | our $DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | *DEBUG = \$HTTP::Daemon::DEBUG; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | ▶ | use HTTP::Request (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | ▶ | use HTTP::Response (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | ▶ | use HTTP::Status; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | ▶ | use HTTP::Date qw(time2str); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | ▶ | use LWP::MediaTypes qw(guess_media_type); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # "\r\n" is not portable | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | my $CRLF = "\015\012"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | my $HTTP_1_0 = _http_version("HTTP/1.0"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | my $HTTP_1_1 = _http_version("HTTP/1.1"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | sub get_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | ▶ | my ($self, $only_headers) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_request: called CC=54 SCAR=57.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 5 | ▶ | if (${*$self}{'httpd_nomore'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->reason("No more requests from this connection"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | $self->reason(""); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 5 | my $buf = ${*$self}{'httpd_rbuf'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 5 | ▶ | $buf = "" unless defined $buf; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | my $timeout = ${*$self}{'io_socket_timeout'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | my $fdset = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 5 | vec($fdset, $self->fileno, 1) = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 5 | local ($_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | READ_HEADER: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 5 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # loop until we have the whole header in $buf | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 10 | $buf =~ s/^(?:\015?\012)+//; # ignore leading blank lines | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 10 | ▶ | if ($buf =~ /\012/) { # potential, has at least one line | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 5 | ▶ | if ($buf =~ /^\w+[^\012]+HTTP\/\d+\.\d+\015?\012/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 5 | ▶ | if ($buf =~ /\015?\012\015?\012/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 5 | last READ_HEADER; # we have it | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | elsif (length($buf) > 16 * 1024) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->send_error(413); # REQUEST_ENTITY_TOO_LARGE | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->reason("Very long header"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | last READ_HEADER; # HTTP/0.9 client | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | elsif (length($buf) > 16 * 1024) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $self->send_error(414); # REQUEST_URI_TOO_LARGE | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | $self->reason("Very long first line"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 5 | ▶ | print STDERR "Need more data for complete header\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 5 | ▶ | return unless $self->_need_more($buf, $timeout, $fdset); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 5 | ▶ | if ($buf !~ s/^(\S+)[ \t]+(\S+)(?:[ \t]+(HTTP\/\d+\.\d+))?[^\012]*\012//) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ${*$self}{'httpd_client_proto'} = _http_version("HTTP/1.0"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $self->send_error(400); # BAD_REQUEST | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $self->reason("Bad request line: $buf"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 5 | my $method = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 5 | my $uri = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 5 | ▶ | my $proto = $3 || "HTTP/0.9"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$3 || 'HTTP/0.9'
MC/DC0%0/1
$3 || 'HTTP/0.9'
$3
Truth table50%1/2
A
A= $3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | ▶ | $uri = "http://$uri" if $method eq "CONNECT"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 5 | $uri = $HTTP::URI_CLASS->new($uri, $self->daemon->url); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | my $r = HTTP::Request->new($method, $uri); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 5 | $r->protocol($proto); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 5 | ${*$self}{'httpd_client_proto'} = $proto = _http_version($proto); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 5 | ${*$self}{'httpd_head'} = ($method eq "HEAD"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 5 | ▶ | if ($proto >= $HTTP_1_0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # we expect to find some headers | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | my ($key, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | HEADER: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 5 | ▶ | while ($buf =~ s/^([^\012]*)\012//) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 26 | $_ = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 26 | s/\015$//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 26 | ▶ | if (/^([^:\s]+)\s*:\s*(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 21 | ▶ | $r->push_header($key, $val) if $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 21 | ($key, $val) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | elsif (/^\s+(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $val .= " $1"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 5 | last HEADER; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 5 | ▶ | $r->push_header($key, $val) if $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 5 | my $conn = $r->header('Connection'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 5 | ▶ | if ($proto >= $HTTP_1_1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 5 | ▶ | ${*$self}{'httpd_nomore'}++ if $conn && lc($conn) =~ /\bclose\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$conn and lc($conn) =~ /\bclose\b/
MC/DC50%1/2
$conn and lc($conn) =~ /\bclose\b/
$conn
lc($conn) =~ /\bclose\b/
Truth table66%2/3
A and B
A= $connB= lc($conn) =~ /\bclose\b/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | ${*$self}{'httpd_nomore'}++ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$conn and lc($conn) =~ /\bkeep-alive\b/
MC/DC0%0/2
$conn and lc($conn) =~ /\bkeep-alive\b/
$conn
lc($conn) =~ /\bkeep-alive\b/
Truth table0%0/3
A and B
A= $connB= lc($conn) =~ /\bkeep-alive\b/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | unless $conn && lc($conn) =~ /\bkeep-alive\b/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 5 | ▶ | if ($only_headers) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ${*$self}{'httpd_rbuf'} = $buf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | return $r; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # Find out how much content to read | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | my $te = $r->header('Transfer-Encoding'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | my $ct = $r->header('Content-Type'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | my $len = $r->header('Content-Length'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # Act on the Expect header, if it's there | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 5 | for my $e ($r->header('Expect')) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if (lc($e) eq '100-continue') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $self->send_status_line(100); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $self->send_crlf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $self->send_error(417); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $self->reason("Unsupported Expect header value"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 5 | ▶ | if ($te && lc($te) eq 'chunked') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$te and lc $te eq "chunked"
MC/DC50%1/2
$te and lc $te eq "chunked"
$te
lc $te eq "chunked"
Truth table66%2/3
A and B
A= $teB= lc $te eq "chunked"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # Handle chunked transfer encoding | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | my $body = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | CHUNK: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 4 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1032 | ▶ | print STDERR "Chunked\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1032 | ▶ | if ($buf =~ s/^([^\012]*)\012//) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1031 | my $chunk_head = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1031 | ▶ | unless ($chunk_head =~ /^([0-9A-Fa-f]+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $self->send_error(400); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $self->reason("Bad chunk header $chunk_head"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1031 | my $size = hex($1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1031 | ▶ | last CHUNK if $size == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1027 | my $missing = $size - length($buf) + 2; # 2=CRLF at chunk end | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | # must read until we have a complete chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1027 | ▶ | while ($missing > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 555 | ▶ | print STDERR "Need $missing more bytes\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 555 | my $n = $self->_need_more($buf, $timeout, $fdset); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 555 | ▶ | return unless $n; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 555 | $missing -= $n; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1027 | $body .= substr($buf, 0, $size); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1027 | substr($buf, 0, $size + 2) = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | # need more data in order to have a complete chunk header | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | ▶ | return unless $self->_need_more($buf, $timeout, $fdset); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 4 | $r->content($body); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # pretend it was a normal entity body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 4 | $r->remove_header('Transfer-Encoding'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 4 | $r->header('Content-Length', length($body)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 4 | my ($key, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | FOOTER: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 4 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 4 | ▶ | if ($buf !~ /\012/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # need at least one line to look at | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | return unless $self->_need_more($buf, $timeout, $fdset); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | $buf =~ s/^([^\012]*)\012//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 4 | $_ = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 4 | s/\015$//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 4 | ▶ | if (/^([\w\-]+)\s*:\s*(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | $r->push_header($key, $val) if $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ($key, $val) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | elsif (/^\s+(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $val .= " $1"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | elsif (!length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 4 | last FOOTER; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $self->reason("Bad footer syntax"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 4 | ▶ | $r->push_header($key, $val) if $key; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | elsif ($te) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $self->send_error(501); # Unknown transfer encoding | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $self->reason("Unknown transfer encoding '$te'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | elsif ($len) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # Plain body specified by "Content-Length" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | my $missing = $len - length($buf); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | ▶ | while ($missing > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | print "Need $missing more bytes of content\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | my $n = $self->_need_more($buf, $timeout, $fdset); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | return unless $n; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | $missing -= $n; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1 | ▶ | if (length($buf) > $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $r->content(substr($buf, 0, $len)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | substr($buf, 0, $len) = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | $r->content($buf); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | $buf = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | ▶ | elsif ($ct && $ct =~ m/^multipart\/\w+\s*;.*boundary\s*=\s*("?)(\w+)\1/i) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ct and $ct =~ m[^multipart/\w+\s*;.*boundary\s*=\s*("?)(\w+)\1]i
MC/DC0%0/2
$ct and $ct =~ m[^multipart/\w+\s*;.*boundary\s*=\s*("?)(\w+)\1]i
$ct
$ct =~ m[^multipart/\w+\s*;.*boundary\s*=\s*("?)(\w+)\1]i
Truth table0%0/3
A and B
A= $ctB= $ct =~ m[^multipart/\w+\s*;.*boundary\s*=\s*("?)(\w+)\1]i
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # Handle multipart content type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $boundary = "$CRLF--$2--"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $index; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $index = index($buf, $boundary); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | last if $index >= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # end marker not yet found | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | return unless $self->_need_more($buf, $timeout, $fdset); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $index += length($boundary); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $r->content(substr($buf, 0, $index)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | substr($buf, 0, $index) = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 5 | ${*$self}{'httpd_rbuf'} = $buf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 5 | $r; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | sub _need_more { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 561 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_need_more: called CC=8 SCAR=32.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | #my($buf,$timeout,$fdset) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 561 | ▶ | if ($_[1]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my ($timeout, $fdset) = @_[1, 2]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | print STDERR "select(,,,$timeout)\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $n = select($fdset, undef, undef, $timeout); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | unless ($n) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | $self->reason(defined($n) ? "Timeout" : "select: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 561 | ▶ | print STDERR "sysread()\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 561 | my $n = sysread($self, $_[0], 2048, length($_[0])); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 561 | ▶ | $self->reason(defined($n) ? "Client closed" : "sysread: $!") unless $n; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 561 | $n; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | sub read_buffer { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_buffer: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my $old = ${*$self}{'httpd_rbuf'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ${*$self}{'httpd_rbuf'} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | $old; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | sub reason { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reason: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 5 | my $old = ${*$self}{'httpd_reason'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 5 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 5 | ${*$self}{'httpd_reason'} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 5 | $old; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | sub proto_ge { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
proto_ge: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ${*$self}{'httpd_client_proto'} >= _http_version(shift); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | sub _http_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 9 | ▶ | local ($_) = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_http_version: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 9 | ▶ | return 0 unless m,^(?:HTTP/)?(\d+)\.(\d+)$,i; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 9 | $1 * 1000 + $2; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | sub antique_client { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 15 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
antique_client: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 15 | ${*$self}{'httpd_client_proto'} < $HTTP_1_0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | sub force_last_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
force_last_request: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 5 | ${*$self}{'httpd_nomore'}++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | sub head_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
head_request: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 5 | ${*$self}{'httpd_head'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | sub send_status_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 5 | ▶ | my ($self, $status, $message, $proto) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_status_line: called CC=7 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 5 | ▶ | return if $self->antique_client; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 5 | ▶ | $status ||= RC_OK; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$status ||= 200
MC/DC0%0/1
$status ||= 200
$status
Truth table50%1/2
A
A= $status
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 5 | ▶ | $message ||= status_message($status) || ""; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$message ||= &status_message($status) || ""
&status_message($status) || ''
MC/DC0%0/2
$message ||= &status_message($status) || ""
$message
&status_message($status)
Truth table33%1/3
A ||= B
A= $messageB= &status_message($status)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 5 | ▶ | $proto ||= $HTTP::Daemon::PROTO || "HTTP/1.1"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$proto ||= $HTTP::Daemon::PROTO || "HTTP/1.1"
$HTTP::Daemon::PROTO || 'HTTP/1.1'
MC/DC0%0/2
$proto ||= $HTTP::Daemon::PROTO || "HTTP/1.1"
$proto
$HTTP::Daemon::PROTO
Truth table33%1/3
A ||= B
A= $protoB= $HTTP::Daemon::PROTO
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 5 | print $self "$proto $status $message$CRLF"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | sub send_crlf { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_crlf: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | print $self $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | sub send_basic_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_basic_header: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 5 | ▶ | return if $self->antique_client; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 5 | $self->send_status_line(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 5 | print $self "Date: ", time2str(time), $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 5 | my $product = $self->daemon->product_tokens; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 5 | ▶ | print $self "Server: $product$CRLF" if $product; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | sub send_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_header: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my ($k, $v) = splice(@_, 0, 2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | $v = "" unless defined($v); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | print $self "$k: $v$CRLF"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | sub send_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_response: called CC=17 SCAR=44.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 5 | my $res = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 5 | ▶ | if (!ref $res) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | ▶ | $res ||= RC_OK; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$res ||= 200
MC/DC0%0/1
$res ||= 200
$res
Truth table0%0/2
A
A= $res
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | $res = HTTP::Response->new($res, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 5 | my $content = $res->content; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 5 | my $chunked; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 5 | ▶ | unless ($self->antique_client) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 5 | my $code = $res->code; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 5 | $self->send_basic_header($code, $res->message, $res->protocol); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 5 | ▶ | if ($code =~ /^(1\d\d|[23]04)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # make sure content is empty | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | $res->remove_header("Content-Length"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | $content = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | ▶ | elsif ($res->request && $res->request->method eq "HEAD") { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$res->request and $res->request->method eq "HEAD"
MC/DC0%0/2
$res->request and $res->request->method eq "HEAD"
$res->request
$res->request->method eq "HEAD"
Truth table33%1/3
A and B
A= $res->requestB= $res->request->method eq "HEAD"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | # probably OK | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | elsif (ref($content) eq "CODE") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | if ($self->proto_ge("HTTP/1.1")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $res->push_header("Transfer-Encoding" => "chunked"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | $chunked++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | $self->force_last_request; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | elsif (length($content)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 5 | $res->header("Content-Length" => length($content)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | $self->force_last_request; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | $res->header('connection', 'close'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 5 | print $self $res->headers_as_string($CRLF); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 5 | print $self $CRLF; # separates headers and content | |||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 5 | ▶ | if ($self->head_request) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | # no content | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | elsif (ref($content) eq "CODE") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | my $chunk = &$content(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | last unless defined($chunk) && length($chunk); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $chunk and length $chunk
MC/DC0%0/2
defined $chunk and length $chunk
defined $chunk
length $chunk
Truth table0%0/3
A and B
A= defined $chunkB= length $chunk
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | if ($chunked) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | printf $self "%x%s%s%s", length($chunk), $CRLF, $chunk, $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | print $self $chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | print $self "0$CRLF$CRLF" if $chunked; # no trailers either | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | elsif (length $content) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 5 | print $self $content; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | sub send_redirect { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | my ($self, $loc, $status, $content) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_redirect: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | ▶ | $status ||= RC_MOVED_PERMANENTLY; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$status ||= 301
MC/DC0%0/1
$status ||= 301
$status
Truth table0%0/2
A
A= $status
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | Carp::croak("Status '$status' is not redirect") unless is_redirect($status); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $self->send_basic_header($status); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | my $base = $self->daemon->url; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | $loc = $HTTP::URI_CLASS->new($loc, $base) unless ref($loc); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | $loc = $loc->abs($base); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | print $self "Location: $loc$CRLF"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | if ($content) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | ▶ | my $ct = $content =~ /^\s*</ ? "text/html" : "text/plain"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | print $self "Content-Type: $ct$CRLF"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | print $self $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | ▶ | print $self $content if $content && !$self->head_request; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$content and not $self->head_request
MC/DC0%0/2
$content and not $self->head_request
$content
not $self->head_request
Truth table0%0/3
A and not(B)
A= $contentB= not $self->head_request
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | $self->force_last_request; # no use keeping the connection open | |||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | sub send_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | ▶ | my ($self, $status, $error) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_error: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | $status ||= RC_BAD_REQUEST; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$status ||= 400
MC/DC0%0/1
$status ||= 400
$status
Truth table0%0/2
A
A= $status
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | Carp::croak("Status '$status' is not an error") unless is_error($status); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | my $mess = status_message($status); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | ▶ | $error ||= ""; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$error ||= ""
MC/DC0%0/1
$error ||= ""
$error
Truth table0%0/2
A
A= $error
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | $mess = <<EOT; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | <title>$status $mess</title> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | <h1>$status $mess</h1> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | $error | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | EOT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | unless ($self->antique_client) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | $self->send_basic_header($status); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | print $self "Content-Type: text/html$CRLF"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | print $self "Content-Length: " . length($mess) . $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | print $self $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | print $self $mess unless $self->head_request; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | $status; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | sub send_file_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | ▶ | my ($self, $file) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_file_response: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | ▶ | if (-d $file) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | $self->send_dir($file); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | elsif (-f _) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | # plain file | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | local (*F); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | ▶ | sysopen(F, $file, 0) or return $self->send_error(RC_FORBIDDEN); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | binmode(F); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | my ($ct, $ce) = guess_media_type($file); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | my ($size, $mtime) = (stat _)[7, 9]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | unless ($self->antique_client) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | $self->send_basic_header; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | print $self "Content-Type: $ct$CRLF"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | ▶ | print $self "Content-Encoding: $ce$CRLF" if $ce; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | print $self "Content-Length: $size$CRLF" if $size; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | ▶ | print $self "Last-Modified: ", time2str($mtime), "$CRLF" if $mtime; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | print $self $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | $self->send_file(\*F) unless $self->head_request; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | return RC_OK; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $self->send_error(RC_NOT_FOUND); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | sub send_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | my ($self, $dir) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_dir: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | $self->send_error(RC_NOT_FOUND) unless -d $dir; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | $self->send_error(RC_NOT_IMPLEMENTED); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | sub send_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | my ($self, $file) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_file: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | my $opened = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | local (*FILE); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | if (!ref($file)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | open(FILE, $file) || return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | binmode(FILE); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | $file = \*FILE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | $opened++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | my $cnt = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | my $buf = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | my $n; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | while ($n = sysread($file, $buf, 8 * 1024)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | ▶ | last if !$n; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | $cnt += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | print $self $buf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | close($file) if $opened; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | $cnt; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | sub daemon { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
daemon: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 10 | ${*$self}{'httpd_daemon'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||