| 1 | package Kossy::Response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use parent qw/Plack::Response/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use HTTP::Headers::Fast; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Cookie::Baker; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | our $VERSION = '0.50'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | our $DIRECT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | our $SECURITY_HEADER = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 34 | ▶ | my ($class, $rc, $headers, $content) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 34 | ▶ | if ( defined $headers ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 30 | ▶ | if (ref $headers eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 12 | ▶ | Carp::carp("Odd number of headers") if @$headers % 2 != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 12 | $headers = HTTP::Headers::Fast->new(@$headers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } elsif (ref $headers eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $headers = HTTP::Headers::Fast->new(%$headers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 34 | ▶ | defined $rc ? ( status => $rc ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | defined $content ? ( body => $content ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | defined $headers ? ( headers => $headers ) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sub headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 30 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headers: called CC=6 SCAR=29.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 30 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $headers = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if (ref $headers eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | Carp::carp("Odd number of headers") if @$headers % 2 != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $headers = HTTP::Headers::Fast->new(@$headers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } elsif (ref $headers eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $headers = HTTP::Headers::Fast->new(%$headers); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return $self->{headers} = $headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 30 | ▶ | return $self->{headers} ||= HTTP::Headers::Fast->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"headers"} ||= "HTTP::Headers::Fast"->new
MC/DC0%0/2
$self->{"headers"} ||= "HTTP::Headers::Fast"->new
$self->{"headers"}
"HTTP::Headers::Fast"->new
Truth table66%2/3
A ||= B
A= $self->{"headers"}B= "HTTP::Headers::Fast"->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | sub _body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 29 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_body: called CC=7 SCAR=20.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 29 | my $body = $self->body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 29 | ▶ | $body = [] unless defined $body; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 29 | ▶ | if (!ref $body or Scalar::Util::blessed($body) && overload::Method($body, q("")) && !$body->can('getline')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
not ref $body or builtin::blessed($body) and overload::Method($body, "\"\"") and not $body->can("getline")
builtin::blessed($body) and overload::Method($body, "\"\"") and not $body->can("getline")
builtin::blessed($body) and overload::Method($body, "\"\"")
MC/DC25%1/4
not ref $body or builtin::blessed($body) and overload::Method($body, "\"\"") and not $body->can("getline")
not ref $body
builtin::blessed($body)
overload::Method($body, "\"\"")
not $body->can("getline")
Truth table40%2/5
not(A) or B and C and not(D)
A= not ref $bodyB= builtin::blessed($body)C= overload::Method($body, "\"\"")D= not $body->can("getline")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 14 | ▶ | return [ Encode::encode_utf8($body) ] if Encode::is_utf8($body); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 9 | return [ $body ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 15 | return $body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | sub finalize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 29 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finalize: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 29 | ▶ | return $DIRECT if $DIRECT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 29 | ▶ | Carp::croak "missing status" unless $self->status(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 29 | my @headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | $self->headers->scan(sub{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 38 | ▶ | my ($k,$v) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 38 | ▶ | return if $SECURITY_HEADER && $k eq 'X-XSS-Protection'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Kossy::Response::SECURITY_HEADER and $k eq "X-XSS-Protection"
MC/DC0%0/2
$Kossy::Response::SECURITY_HEADER and $k eq "X-XSS-Protection"
$Kossy::Response::SECURITY_HEADER
$k eq "X-XSS-Protection"
Truth table66%2/3
A and B
A= $Kossy::Response::SECURITY_HEADERB= $k eq "X-XSS-Protection"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 38 | $v =~ s/\015\012[\040|\011]+/chr(32)/ge; # replace LWS with a single SP | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 38 | $v =~ s/\015|\012//g; # remove CR and LF since the char is invalid here | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 38 | push @headers, $k, $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 29 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 29 | ▶ | while (my($name, $val) = each %{$self->cookies}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | my $cookie = bake_cookie($name, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | push @headers, 'Set-Cookie' => $cookie; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 29 | ▶ | push @headers, 'X-XSS-Protection' => 1 if $SECURITY_HEADER; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 29 | $self->status, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | \@headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | $self->_body, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||