line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::AmazonS3::Simple::HTTP; |
2
|
2
|
|
|
2
|
|
477
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
49
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
44
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
225
|
use HTTP::Request; |
|
2
|
|
|
|
|
14402
|
|
|
2
|
|
|
|
|
64
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
540
|
use Class::Tiny qw(http_client signer auto_region region secure host); |
|
2
|
|
|
|
|
2528
|
|
|
2
|
|
|
|
|
7
|
|
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
|
1053
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
6
|
foreach my $req ( qw/http_client signer auto_region region secure host/ ) { |
41
|
12
|
50
|
|
|
|
205
|
die "$req attribute required" if! defined $self->$req; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 request(%options) |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
sub request { |
49
|
6
|
|
|
6
|
|
5629
|
my ($self, %options) = @_; |
50
|
|
|
|
|
|
|
|
51
|
6
|
100
|
|
|
|
19
|
$options{method} = 'GET' if !defined $options{method}; |
52
|
|
|
|
|
|
|
|
53
|
6
|
|
|
|
|
13
|
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
|
|
|
|
|
14
|
$self->_uri(%options), |
60
|
|
|
|
|
|
|
['x-amz-content-sha256' => 'UNSIGNED-PAYLOAD'] |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
6480
|
$self->signer->sign($request, $self->region, 'UNSIGNED-PAYLOAD'); |
64
|
|
|
|
|
|
|
|
65
|
4
|
50
|
|
|
|
3941
|
print $request->as_string() . "\n" if $ENV{AWS_S3_DEBUG}; |
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
610
|
my $response = $self->http_client->request($request, $options{ content_to_file }); |
68
|
|
|
|
|
|
|
|
69
|
4
|
50
|
|
|
|
4333
|
print $response->as_string() . "\n" if $ENV{AWS_S3_DEBUG}; |
70
|
|
|
|
|
|
|
|
71
|
4
|
100
|
66
|
|
|
126
|
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
|
|
|
|
14
|
if ($response->content() =~ m{([-\w]+)}) { |
75
|
1
|
|
|
|
|
10
|
my $region = $1; |
76
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
7
|
print "# set region to: $region\n" if $ENV{AWS_S3_DEBUG}; |
78
|
1
|
|
|
|
|
16
|
$self->region($region); |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
8
|
$response = request(@_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
4
|
50
|
|
|
|
40
|
if ($response->is_success()) { |
85
|
4
|
|
|
|
|
45
|
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
|
|
10
|
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
|
|
|
|
83
|
$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
|
|
|
|
|
|
|
|