S3/HTTPRequest.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 1 totaltotal 94.9% 75 / 79 CC 4 SCAR 5.9
CC
4
Cov
97%
http_request
4.0
__ANON__
1.1
BEGIN
1.0
CRAP 1.8
« S3.pm ↑ Summary S3/Types.pm »
1  
2 package AWS::S3::HTTPRequest;
3  
4 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use AWS::S3::Signer::V4;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use HTTP::Date ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 with 'AWS::S3::Roles::Bucket';
15  
16 2 my $METADATA_PREFIX = 'x-amz-meta-';
17 2 my $AMAZON_HEADER_PREFIX = 'x-amz-';
18  
19 2 enum 'HTTPMethod' => [qw( HEAD GET PUT POST DELETE )];
20  
21 2 has 's3' => (
22 is => 'ro',
23 required => 1,
24 isa => 'AWS::S3',
25 );
26  
27 2 has 'method' => (
28 is => 'ro',
29 required => 1,
30 isa => 'HTTPMethod'
31 );
32  
33 2 has 'path' => (
34 is => 'ro',
35 required => 1,
36 isa => 'Str',
37 );
38  
39 2 class_type( 'HTTP::Headers' );
40  
41 coerce 'HTTP::Headers'
42 => from 'HashRef'
43 0 ▶ => via { my $h = HTTP::Headers->new( %$_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
44  
45 has 'headers' => (
46 is => 'ro',
47 required => 1,
48 isa => 'HTTP::Headers',
49 lazy => 1,
50 4 ▶ default => sub { HTTP::Headers->new() },
Subroutine __ANON__: called CC=1 SCAR=0.0
51 2 coerce => 1,
52 );
53  
54 2 has 'content' => (
55 is => 'ro',
56 required => 1,
57 isa => 'Str|ScalarRef|CodeRef',
58 default => '',
59 );
60  
61 has 'metadata' => (
62 is => 'ro',
63 required => 1,
64 isa => 'HashRef',
65 4 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
66 2 );
67  
68 2 has 'contenttype' => (
69 is => 'ro',
70 required => 0,
71 isa => 'Str',
72 );
73  
74 # Make the HTTP::Request object:
75 4 ▶sub http_request {
Subroutine http_request: called CC=4 SCAR=13.9
Pod undocumented
76 4 my $s = shift;
77 4 my $method = $s->method;
78 4 my $headers = $s->headers;
79 4 my $content = $s->content;
80 4 my $metadata = $s->metadata;
81  
82 4 my $uri = $s->bucket_uri( $s->path );
83  
84 4 $headers->header( 'Date' => HTTP::Date::time2str( time ) );
85 4 $headers->header( 'Host' => URI->new( $uri )->host );
86  
87 4 ▶ if ( $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content) 2 2 4
88 2 $headers->header( 'content-length' => length $content );
89 2 ▶ $headers->header( 'content-type' => $method eq 'GET' ? '' : 'text/plain' );
Branch: 1 branch
BranchTrueFalseTotal
$method eq 'GET' ? : 0 2 2
90 }
91  
92 4 my $request = HTTP::Request->new( $method, $uri, $headers, $content );
93  
94 # sign with a v4 signature, as the other requests do
95 4 my $s3 = $s->s3;
96 4 my $signer = AWS::S3::Signer::V4->new(
97 -access_key => $s3->access_key_id,
98 -secret_key => $s3->secret_access_key,
99 );
100  
101 4 ▶ $request->header( 'X-Amz-Security-Token' => $s3->session_token )
Branch: 1 branch
BranchTrueFalseTotal
if defined $s3->session_token 2 2 4
102 if defined $s3->session_token;
103  
104 4 my $digest = Digest::SHA::sha256_hex( $request->content );
105 4 $request->header( 'X-Amz-Content-SHA256' => $digest );
106 4 $signer->sign( $request, $s3->region, $digest );
107  
108 4 return $request;
109 } # end http_request()
110  
111 2 __PACKAGE__->meta->make_immutable;
112  
« S3.pm ↑ Summary S3/Types.pm »