File Coverage

blib/lib/Paws/Net/LWPCaller.pm
Criterion Covered Total %
statement 20 20 100.0
branch 3 4 75.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 2 0.0
total 30 34 88.2


line stmt bran cond sub pod time code
1             package Paws::Net::LWPCaller;
2             # This caller uses LWP::UserAgent -- thus HTTPS proxies are supported.
3 3     3   1922 use Moose;
  3         8  
  3         21  
4             with 'Paws::Net::RetryCallerRole', 'Paws::Net::CallerRole';
5              
6             has debug => ( is => 'rw', required => 0, default => sub { 0 } );
7             has ua => (is => 'rw', required => 1, lazy => 1,
8             default => sub {
9 3     3   21638 use LWP::UserAgent;
  3         43608  
  3         648  
10             my $ua = LWP::UserAgent->new(timeout => 60);
11             $ua->env_proxy;
12             push @{ $ua->requests_redirectable }, 'POST';
13             return $ua;
14             }
15             );
16              
17             sub send_request {
18 10     10 0 36 my ($self, $service, $call_object) = @_;
19              
20 10         84 my $requestObj = $service->prepare_request_for_call($call_object);
21              
22 10         39 my $headers = $requestObj->header_hash;
23             # HTTP::Tiny derives the Host header from the URL. It's an error to set it.
24 10         29 delete $headers->{Host};
25              
26 10         260 my $method = lc $requestObj->method;
27 10 50       232 my $response = $self->ua->$method(
28             $requestObj->url,
29             %$headers,
30             (defined $requestObj->content)?(Content => $requestObj->content):(),
31             );
32            
33              
34 10         157989 my $lcheaders = {};
35 10     30   38 $response->headers->scan(sub { $lcheaders->{ lc$_[0] } = $_[1] });
  30         589  
36              
37 10         79 return($response->code, $response->content, $lcheaders);
38             }
39              
40             sub caller_to_response {
41 28     28 0 109 my ($self, $service, $call_object, $status, $content, $headers) = @_;
42            
43 28 100 66     181 if ($status == 500 and $headers->{'client-warning'} eq 'Internal response') {
44 15         423 return Paws::Exception->new(message => $content, code => 'ConnectionError', request_id => '');
45             } else {
46 13         74 return $service->handle_response($call_object, $status, $content, $headers);
47             }
48             }
49             1;