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