App-MtAws
view release on metacpan or search on metacpan
lib/App/MtAws/GlacierRequest.pm view on Meta::CPAN
my ($self, $uploadid, $dataref, $offset, $part_final_hash) = @_;
$uploadid||confess;
($self->{dataref} = $dataref)||confess;
defined($offset)||confess;
($self->{part_final_hash} = $part_final_hash)||confess;
$self->_calc_data_hash;
$self->{url} = "/$self->{account_id}/vaults/$self->{vault}/multipart-uploads/$uploadid";
$self->{method} = 'PUT';
$self->add_header('Content-Type', 'application/octet-stream');
$self->add_header('Content-Length', length(${$self->{dataref}}));
$self->add_header('x-amz-content-sha256', $self->{data_sha256});
$self->add_header('x-amz-sha256-tree-hash', $self->{part_final_hash});
my ($start, $end) = ($offset, $offset+length(${$self->{dataref}})-1 );
$self->add_header('Content-Range', "bytes ${start}-${end}/*");
my $resp = $self->perform_lwp();
return $resp ? 1 : undef;
}
lib/App/MtAws/GlacierRequest.pm view on Meta::CPAN
return ($resp->content, $itype);
}
sub create_vault
{
my ($self, $vault_name) = @_;
confess unless defined($vault_name);
$self->{url} = "/$self->{account_id}/vaults/$vault_name";
$self->{method} = 'PUT';
my $resp = $self->perform_lwp();
return $resp ? $resp->header('x-amzn-RequestId') : undef;
}
sub delete_vault
{
my ($self, $vault_name) = @_;
confess unless defined($vault_name);
lib/App/MtAws/GlacierRequest.pm view on Meta::CPAN
my $url = $self->{protocol} ."://$self->{host}$self->{url}";
$url = $self->{protocol} ."://$ENV{MTGLACIER_FAKE_HOST}$self->{url}" if $ENV{MTGLACIER_FAKE_HOST};
if ($self->{protocol} eq 'https') {
if ($ENV{MTGLACIER_FAKE_HOST}) {
$ua->ssl_opts( verify_hostname => 0, SSL_verify_mode=>0); #Hostname mismatch causes LWP to error.
} else {
$ua->ssl_opts( verify_hostname => 1, SSL_verify_mode=>1);
}
}
$url .= "?$self->{params_s}" if $self->{params_s};
if ($self->{method} eq 'PUT') {
$req = HTTP::Request->new(PUT => $url, undef, $self->{dataref});
} elsif ($self->{method} eq 'POST') {
if ($self->{dataref}) {
$req = HTTP::Request->new(POST => $url, [Content_Type => 'form-data'], ${$self->{dataref}});
} else {
$req = HTTP::Request->new(POST => $url );
}
} elsif ($self->{method} eq 'DELETE') {
$req = HTTP::Request->new(DELETE => $url);
} elsif ($self->{method} eq 'GET') {
$req = HTTP::Request->new(GET => $url);
t/integration/lwp.t view on Meta::CPAN
print $c $s;
}
# correct request, but HTTP 400 with exception in JSON
{
# TODO: seems some versions of LWP raise this warnign, actually move to GlacierRequest
open F, ">$tmpfile";
close F;
no warnings 'redefine';
local *App::MtAws::GlacierRequest::_max_retries = sub { 1 };
local *App::MtAws::GlacierRequest::_sleep = sub { };
for my $method (qw/GET PUT POST DELETE/) {
for my $action (qw/chunked_throttling_exception/) {
my $writer = App::MtAws::HttpFileWriter->new(tempfile => $tmpfile);
my ($g, $resp, $err) = make_glacier_request($method, $action, {%common_options},
{writer => $writer, expected_size => $test_size, dataref => \''});
is -s $tmpfile, 0;
is $err->{code}, 'too_many_tries'; # TODO: test with cmp_deep and exception()
is $g->{last_retry_reason}, 'ThrottlingException', "ThrottlingException for $method,$action";
}
}
}
t/integration/lwp.t view on Meta::CPAN
my ($g, $resp, $err) = make_glacier_request('GET', "content_length/$test_size/$test_size", {%common_options},
{writer => $writer, expected_size => $test_size+1});
is $err->{code}, 'wrong_file_size_in_journal'; # TODO: test with cmp_deep and exception()
is -s $tmpfile, 0;
}
# correct response, size is zero
{
no warnings 'redefine';
local *App::MtAws::GlacierRequest::_sleep = sub { die };
for (qw/GET PUT POST DELETE/) {
my ($g, $resp, $err) = make_glacier_request($_, "empty_response", {%common_options}, {dataref=>\''});
ok $resp && !$err, "empty response should work for $_ method";
}
}
# data truncated, writer not used
{
no warnings 'redefine';
local *App::MtAws::GlacierRequest::_max_retries = sub { 1 };
local *App::MtAws::GlacierRequest::_sleep = sub { };
for (qw/GET PUT POST DELETE/) {
my ($g, $resp, $err) = make_glacier_request($_, "content_length/499/501", {%common_options}, {dataref=>\''});
is $err->{code}, 'too_many_tries', "Code for $_";
is $g->{last_retry_reason}, 'Unexpected end of data', "Reason for $_";
}
}
# correct response, no size header sent (chunked response? or maybe http/1.0)
{
open F, ">$tmpfile";
close F;
( run in 0.522 second using v1.01-cache-2.11-cpan-c6e0e5ac2a7 )