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