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