| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::AmazonS3::Simple::HTTP; |
|
2
|
2
|
|
|
2
|
|
708
|
use strict; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
51
|
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
48
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
420
|
use HTTP::Request; |
|
|
2
|
|
|
|
|
14873
|
|
|
|
2
|
|
|
|
|
68
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
938
|
use Class::Tiny qw(http_client signer auto_region region secure host); |
|
|
2
|
|
|
|
|
4518
|
|
|
|
2
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Net::AmazonS3::Simple::HTTP - request formater and caller |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 METHODS |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 new(%attributes) |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head3 %attributes |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head4 http_client |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head4 signer |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head4 auto_region |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head4 region |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head4 secure |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head4 host |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub BUILD { |
|
38
|
2
|
|
|
2
|
0
|
831
|
my ($self) = @_; |
|
39
|
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
4
|
foreach my $req ( qw/http_client signer auto_region region secure host/ ) { |
|
41
|
12
|
50
|
|
|
|
198
|
die "$req attribute required" if! defined $self->$req; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 request(%options) |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
sub request { |
|
49
|
6
|
|
|
6
|
|
2376
|
my ($self, %options) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
6
|
100
|
|
|
|
15
|
$options{method} = 'GET' if !defined $options{method}; |
|
52
|
|
|
|
|
|
|
|
|
53
|
6
|
|
|
|
|
9
|
foreach my $req (qw/bucket path/) { |
|
54
|
10
|
100
|
|
|
|
38
|
die "$req parameter required" if !defined $options{$req}; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $request = HTTP::Request->new( |
|
58
|
|
|
|
|
|
|
$options{method}, |
|
59
|
4
|
|
|
|
|
12
|
$self->_uri(%options), |
|
60
|
|
|
|
|
|
|
['x-amz-content-sha256' => 'UNSIGNED-PAYLOAD'] |
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
6939
|
$self->signer->sign($request, $self->region, 'UNSIGNED-PAYLOAD'); |
|
64
|
|
|
|
|
|
|
|
|
65
|
4
|
50
|
|
|
|
2444
|
print $request->as_string() . "\n" if $ENV{AWS_S3_DEBUG}; |
|
66
|
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
475
|
my $response = $self->http_client->request($request, $options{ content_to_file }); |
|
68
|
|
|
|
|
|
|
|
|
69
|
4
|
50
|
|
|
|
2534
|
print $response->as_string() . "\n" if $ENV{AWS_S3_DEBUG}; |
|
70
|
|
|
|
|
|
|
|
|
71
|
4
|
100
|
66
|
|
|
94
|
if ($self->auto_region && $response->code == 400) { |
|
72
|
|
|
|
|
|
|
#I know - XML don't be parsed with regex, but for this simple case I do it |
|
73
|
|
|
|
|
|
|
#maybe with next versions I use XML::LibXML;) |
|
74
|
1
|
50
|
|
|
|
13
|
if ($response->content() =~ m{([-\w]+)}) { |
|
75
|
1
|
|
|
|
|
8
|
my $region = $1; |
|
76
|
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
6
|
print "# set region to: $region\n" if $ENV{AWS_S3_DEBUG}; |
|
78
|
1
|
|
|
|
|
16
|
$self->region($region); |
|
79
|
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
7
|
$response = request(@_); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
4
|
50
|
|
|
|
37
|
if ($response->is_success()) { |
|
85
|
4
|
|
|
|
|
38
|
return $response; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
die sprintf |
|
89
|
|
|
|
|
|
|
"Unknown response %s:\n:%s", |
|
90
|
|
|
|
|
|
|
$response->message, |
|
91
|
|
|
|
|
|
|
$response->content; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub _uri { |
|
95
|
4
|
|
|
4
|
|
7
|
my ($self, %options) = @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return sprintf |
|
98
|
|
|
|
|
|
|
'%s://%s.%s/%s', |
|
99
|
|
|
|
|
|
|
$self->secure ? 'https' : 'http', |
|
100
|
|
|
|
|
|
|
$options{bucket}, |
|
101
|
|
|
|
|
|
|
$self->host, |
|
102
|
4
|
50
|
|
|
|
74
|
$options{path}; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 LICENSE |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Copyright (C) Avast Software. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
110
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Jan Seidl Eseidl@avast.comE |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
|
119
|
|
|
|
|
|
|
|