Amazon-CloudFront-Thin
view release on metacpan or search on metacpan
lib/Amazon/CloudFront/Thin.pm view on Meta::CPAN
package Amazon::CloudFront::Thin;
use strict;
use warnings;
use URI ();
use URI::Escape ();
use Carp ();
use HTTP::Headers ();
use HTTP::Date ();
use HTTP::Request ();
use Digest::SHA ();
our $VERSION = '0.05';
sub new {
my ($class, @extra) = @_;
my $args;
my $self = {};
if (@extra == 1) {
lib/Amazon/CloudFront/Thin.pm view on Meta::CPAN
. ', SignedHeaders=' . _signed_headers($http_headers)
. ', Signature='
. _calculate_signature(
$self->{aws_secret_access_key},
$url,
$http_headers,
$content
)
);
my $request = HTTP::Request->new('POST', $url, $http_headers, $content);
return $self->ua->request($request);
}
sub _cloudfront_scope {
my ($date) = @_;
return sprintf("%s/us-east-1/cloudfront/aws4_request", $date);
}
sub _format_date {
my ($time) = @_;
lib/Amazon/CloudFront/Thin.pm view on Meta::CPAN
=item * C<aws_secret_access_key> (B<required>)
Your L<< CloudFront credential|/"Amazon CloudFront setup in a Nutshell" >> secret.
=item * C<distribution_id> (B<required>)
The id of the L<< CloudFront distribution|/"Amazon CloudFront setup in a Nutshell" >>
you want to manage.
=item * C<ua> (Optional)
An LWP::UserAgent compatible object (otherwise, LWP::UserAgent will be used).
The object must provide a C<request()> method that receives an HTTP::Request
and returns a response. The responses, whatever they are, will be forwarded
to your call. Also, the object must be able to handle B<HTTPS>. If you don't
want to use LWP::UserAgent, there is a (highly incomplete) list of
alternatives below:
Compatible: L<Furl>, L<LWP::UserAgent>, L<HTTP::Thin>, L<WWW::Curl::Simple>.
Incompatible: L<HTTP::Lite>, L<Hijk>, L<HTTP::Lite>, L<HTTP::Tiny>.
=back
t/04-request.t view on Meta::CPAN
use strict;
use warnings;
package MyAgent;
use Test::More;
sub new { bless {}, shift }
sub request {
my ($self, $req) = @_;
isa_ok $self, 'MyAgent';
isa_ok $req, 'HTTP::Request';
like $req->content, qr{\Q<?xml version="1.0" encoding="UTF-8"?><InvalidationBatch xmlns="http://cloudfront.amazonaws.com/doc/2018-11-05/"><Paths><Quantity>1</Quantity><Items><Path><![CDATA[/some/path]]></Path></Items></Paths><CallerReference>\E\d...
my $headers = $req->headers->as_string;
like $headers, qr{X-Amz-Date: \d{8}T\d{6}Z}, 'headers contain date in iso 8601 (NOT RFC 1123)';
like $headers, qr{Authorization: AWS4-HMAC-SHA256 Credential=123/\d+/us-east-1/cloudfront/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date, Signature=[a-z0-9]{64}}, 'headers contain auth';
like $headers, qr{Host: cloudfront.amazonaws.com}, 'headers contain host';
like $headers, qr{Content-Length: 265}, 'headers contain content-length';
like $headers, qr{Content-Type: text/xml}, 'headers contain content-type';
return 42;
}
( run in 0.481 second using v1.01-cache-2.11-cpan-de7293f3b23 )