| 1 | package HTTP::Engine::ResponseFinalizer; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use CGI::Simple::Cookie; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | sub finalize { | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | my ($class, $req, $res) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finalize: called CC=15 SCAR=38.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | Carp::confess 'argument missing: $res' unless $res; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # protocol | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | $res->protocol( $req->protocol ) unless $res->protocol; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # Content-Length | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | if ($res->body) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # get the length from a filehandle | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | if ((Scalar::Util::blessed($res->body) && $res->body->can('read')) || (ref($res->body) eq 'GLOB')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
builtin::blessed($res->body) and $res->body->can("read") or ref $res->body eq "GLOB"
builtin::blessed($res->body) and $res->body->can("read")
MC/DC0%0/3
builtin::blessed($res->body) and $res->body->can("read") or ref $res->body eq "GLOB"
builtin::blessed($res->body)
$res->body->can("read")
ref $res->body eq "GLOB"
Truth table20%1/5
A and B or C
A= builtin::blessed($res->body)B= $res->body->can("read")C= ref $res->body eq "GLOB"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $st_size = 7; # see perldoc -f stat | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | if (my $size = eval { (stat($res->body))[$st_size] }) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | $res->content_length($size); | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | die "Serving filehandle without a content-length($@)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | use bytes; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | $res->content_length(bytes::length($res->body)); | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $res->content_length(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Errors | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | ▶ | if ($res->status =~ /^(1\d\d|[23]04)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $res->headers->remove_header("Content-Length"); | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $res->body(''); | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | $res->content_type('text/html') unless $res->content_type; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | $res->header(Status => $res->status); | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | $class->_finalize_cookies($res); | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # HTTP/1.1's default Connection: close | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | if ($res->protocol && $res->protocol =~ m!1\.1! && !!!$res->header('Connection')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$res->protocol and $res->protocol =~ /1\.1/ and not !!$res->header("Connection")
$res->protocol and $res->protocol =~ /1\.1/
MC/DC0%0/3
$res->protocol and $res->protocol =~ /1\.1/ and not !!$res->header("Connection")
$res->protocol
$res->protocol =~ /1\.1/
not !!$res->header("Connection")
Truth table25%1/4
A and B and not(C)
A= $res->protocolB= $res->protocol =~ /1\.1/C= not !!$res->header("Connection")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $res->header( Connection => 'close' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | ▶ | $res->body('') if ((defined $req->method) and ($req->method eq 'HEAD')); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $req->method and $req->method eq "HEAD"
MC/DC0%0/2
defined $req->method and $req->method eq "HEAD"
defined $req->method
$req->method eq "HEAD"
Truth table33%1/3
A and B
A= defined $req->methodB= $req->method eq "HEAD"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | sub _finalize_cookies { | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | ▶ | my ($class, $res) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_finalize_cookies: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 6 | my $cookies = $res->cookies; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | my @keys = keys %$cookies; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | ▶ | if (@keys) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | for my $name (@keys) { | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | my $val = $cookies->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | my $cookie = ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | Scalar::Util::blessed($val) | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ? $val | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | : CGI::Simple::Cookie->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | -name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | -value => $val->{value}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | -expires => $val->{expires}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | -domain => $val->{domain}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | -path => $val->{path}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | -secure => ($val->{secure} || 0) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$val->{'secure'} || 0
MC/DC0%0/1
$val->{'secure'} || 0
$val->{'secure'}
Truth table50%1/2
A
A= $val->{'secure'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | $res->headers->push_header('Set-Cookie' => $cookie->as_string); | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||