AWS-Lambda
view release on metacpan or search on metacpan
lib/AWS/Lambda/ResponseWriter.pm view on Meta::CPAN
package AWS::Lambda::ResponseWriter;
use 5.026000;
use utf8;
use strict;
use warnings;
use Carp qw(croak);
use Scalar::Util qw(blessed);
use MIME::Base64 qw(encode_base64);
use HTTP::Tiny;
my %DefaultPort = (
http => 80,
https => 443,
);
sub new {
my $proto = shift;
my $class = ref $proto || $proto;
my %args;
if (@_ == 1 && ref $_[0] eq 'HASH') {
%args = %{$_[0]};
} else {
%args = @_;
}
my $http = $args{http} // HTTP::Tiny->new;
my $response_url = $args{response_url} // die '$LAMBDA_TASK_ROOT is not found';
my $content_type = $args{content_type} // 'application/json';
my $self = bless +{
response_url => $response_url,
http => $http,
handle => undef,
closed => 0,
}, $class;
return $self;
}
sub _request {
my ($self, $content_type) = @_;
my $response_url = $self->{response_url};
my $http = $self->{http};
my ($scheme, $host, $port, $path_query, $auth) = $http->_split_url($response_url);
my $host_port = ($port == $DefaultPort{$scheme} ? $host : "$host:$port");
my $request = {
method => "POST",
scheme => $scheme,
host => $host,
port => $port,
host_port => $host_port,
uri => $path_query,
headers => {
"host" => $host_port,
"content-type" => $content_type,
"transfer-encoding" => "chunked",
"trailer" => "Lambda-Runtime-Function-Error-Type, Lambda-Runtime-Function-Error-Body",
"lambda-runtime-function-response-mode" => "streaming",
},
header_case => {
"host" => "Host",
"content-type" => "Content-Type",
"transfer-encoding" => "Transfer-Encoding",
"trailer" => "Trailer",
"lambda-runtime-function-response-mode" => "Lambda-Runtime-Function-Response-Mode",
( run in 0.934 second using v1.01-cache-2.11-cpan-f56aa216473 )