line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::AmazonS3::Simple::HTTP; |
2
|
2
|
|
|
2
|
|
886
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
71
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
77
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
606
|
use HTTP::Request; |
|
2
|
|
|
|
|
22076
|
|
|
2
|
|
|
|
|
89
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1359
|
use Class::Tiny qw(http_client signer auto_region region secure host); |
|
2
|
|
|
|
|
6993
|
|
|
2
|
|
|
|
|
19
|
|
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
|
2126
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
8
|
foreach my $req ( qw/http_client signer auto_region region secure host/ ) { |
41
|
12
|
50
|
|
|
|
452
|
die "$req attribute required" if! defined $self->$req; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 request(%options) |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
sub request { |
49
|
6
|
|
|
6
|
|
6761
|
my ($self, %options) = @_; |
50
|
|
|
|
|
|
|
|
51
|
6
|
100
|
|
|
|
33
|
$options{method} = 'GET' if !defined $options{method}; |
52
|
|
|
|
|
|
|
|
53
|
6
|
|
|
|
|
18
|
foreach my $req (qw/bucket path/) { |
54
|
10
|
100
|
|
|
|
70
|
die "$req parameter required" if !defined $options{$req}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $request = HTTP::Request->new( |
58
|
|
|
|
|
|
|
$options{method}, |
59
|
4
|
|
|
|
|
21
|
$self->_uri(%options), |
60
|
|
|
|
|
|
|
['x-amz-content-sha256' => 'UNSIGNED-PAYLOAD'] |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
4
|
|
|
|
|
14753
|
$self->signer->sign($request, $self->region, 'UNSIGNED-PAYLOAD'); |
64
|
|
|
|
|
|
|
|
65
|
4
|
50
|
|
|
|
5252
|
print $request->as_string() . "\n" if $ENV{AWS_S3_DEBUG}; |
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
1605
|
my $response = $self->http_client->request($request, $options{ content_to_file }); |
68
|
|
|
|
|
|
|
|
69
|
4
|
50
|
|
|
|
4739
|
print $response->as_string() . "\n" if $ENV{AWS_S3_DEBUG}; |
70
|
|
|
|
|
|
|
|
71
|
4
|
100
|
66
|
|
|
617
|
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
|
|
|
|
18
|
if ($response->content() =~ m{([-\w]+)}) { |
75
|
1
|
|
|
|
|
13
|
my $region = $1; |
76
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
164
|
print "# set region to: $region\n" if $ENV{AWS_S3_DEBUG}; |
78
|
1
|
|
|
|
|
29
|
$self->region($region); |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
11
|
$response = request(@_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
4
|
50
|
|
|
|
101
|
if ($response->is_success()) { |
85
|
4
|
|
|
|
|
77
|
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
|
|
14
|
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
|
|
|
|
140
|
$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
|
|
|
|
|
|
|
|