line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Server::AWSLambda::Response; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
15
|
use Mojo::Base 'Mojo::Message::Response'; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
13
|
|
4
|
2
|
|
|
2
|
|
15328
|
use Mojo::JSON qw(decode_json encode_json); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
102
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
13
|
use MIME::Base64; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
83
|
|
7
|
2
|
|
|
2
|
|
1092
|
use Try::Tiny; |
|
2
|
|
|
|
|
2738
|
|
|
2
|
|
|
|
|
116
|
|
8
|
2
|
|
|
2
|
|
924
|
use JSON::Types; |
|
2
|
|
|
|
|
495
|
|
|
2
|
|
|
|
|
117
|
|
9
|
2
|
|
|
2
|
|
15
|
use Encode; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
890
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub output { |
12
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
50
|
|
|
19
|
my $status = $self->code || 404; |
15
|
1
|
|
|
|
|
15
|
my $headers = $self->headers->to_hash; |
16
|
1
|
|
|
|
|
53
|
my $body = $self->body; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
22
|
my $singleValueHeaders = {}; |
19
|
1
|
|
|
|
|
3
|
my $multiValueHeaders = {}; |
20
|
1
|
|
|
|
|
2
|
foreach my $header (keys %{$headers}) { |
|
1
|
|
|
|
|
4
|
|
21
|
1
|
|
|
|
|
4
|
$singleValueHeaders->{lc $header} = $headers->{$header}; |
22
|
1
|
|
50
|
|
|
2
|
push @{$multiValueHeaders->{lc $header} //= []}, $headers->{$header}; |
|
1
|
|
|
|
|
8
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
3
|
my $type = $singleValueHeaders->{'content-type'}; |
26
|
1
|
|
|
|
|
8
|
my $isBase64Encoded = $type !~ m(^text/.*|application/(:?json|javascript|xml))i; |
27
|
1
|
50
|
|
|
|
7
|
if ($isBase64Encoded) { |
28
|
0
|
|
|
|
|
0
|
$body = encode_base64 $body, ''; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
|
|
|
|
|
|
try { |
32
|
1
|
|
|
1
|
|
83
|
decode_utf8($body, Encode::FB_CROAK | Encode::LEAVE_SRC); |
33
|
|
|
|
|
|
|
} catch { |
34
|
0
|
|
|
0
|
|
0
|
$isBase64Encoded = 1; |
35
|
0
|
|
|
|
|
0
|
$body = encode_base64 $body, ''; |
36
|
1
|
|
|
|
|
10
|
}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return +{ |
40
|
1
|
|
|
|
|
76
|
isBase64Encoded => bool $isBase64Encoded, |
41
|
|
|
|
|
|
|
headers => $singleValueHeaders, |
42
|
|
|
|
|
|
|
multiValueHeaders => $multiValueHeaders, |
43
|
|
|
|
|
|
|
statusCode => number $status, |
44
|
|
|
|
|
|
|
body => string $body, |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |