line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Tiny::FromHTTPRequest; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Perform a request based on a plain HTTP request or HTTP::Request object |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
1439
|
use strict; |
|
3
|
|
|
|
|
24
|
|
|
3
|
|
|
|
|
83
|
|
6
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
81
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1305
|
use parent 'HTTP::Tiny'; |
|
3
|
|
|
|
|
915
|
|
|
3
|
|
|
|
|
16
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
157326
|
use Carp; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
162
|
|
11
|
3
|
|
|
3
|
|
21
|
use Scalar::Util qw(blessed); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
271
|
|
12
|
3
|
|
|
3
|
|
1445
|
use HTTP::Request; |
|
3
|
|
|
|
|
68050
|
|
|
3
|
|
|
|
|
820
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub request { |
17
|
7
|
|
|
7
|
1
|
25153
|
my ($self, @params) = @_; |
18
|
|
|
|
|
|
|
|
19
|
7
|
|
|
|
|
24
|
local $Carp::Internal{ 'HTTP::Tiny::FromHTTPRequest' } = 1; |
20
|
|
|
|
|
|
|
|
21
|
7
|
50
|
|
|
|
28
|
(@_ >= 2 ) |
22
|
|
|
|
|
|
|
or Carp::croak(q/Usage: $http->request(METHOD, URL, [HASHREF])/ . "\n"); |
23
|
|
|
|
|
|
|
|
24
|
7
|
|
|
|
|
23
|
my @methods = qw(get head put post delete); |
25
|
7
|
100
|
100
|
|
|
31
|
if ( !ref $params[0] && grep{ lc $params[0] eq $_ }@methods ) { |
|
20
|
|
|
|
|
81
|
|
26
|
2
|
|
|
|
|
16
|
return $self->SUPER::request( @params ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
10
|
my $request; |
30
|
5
|
100
|
66
|
|
|
63
|
if ( blessed $params[0] and $params[0]->isa('HTTP::Request') ) { |
|
|
50
|
|
|
|
|
|
31
|
3
|
|
|
|
|
9
|
$request = $params[0]; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif ( ! ref $params[0] ) { |
34
|
2
|
|
|
|
|
43
|
$request = HTTP::Request->parse( $params[0] ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
5
|
50
|
|
|
|
684
|
Carp::croak(q/Usage: $http->request(METHOD, URL, [HASHREF])/ . "\n") if !$request; |
38
|
|
|
|
|
|
|
|
39
|
5
|
|
|
|
|
12
|
my %options; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# add headers |
42
|
5
|
|
|
|
|
21
|
$options{headers} = { $request->headers->flatten }; |
43
|
5
|
|
|
|
|
892
|
delete $options{headers}->{Host}; |
44
|
|
|
|
|
|
|
|
45
|
5
|
|
|
|
|
25
|
my $content = $request->content; |
46
|
5
|
100
|
|
|
|
73
|
if ( $content ) { |
47
|
4
|
|
|
|
|
10
|
$options{content} = $content; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
5
|
|
|
|
|
17
|
return $self->SUPER::request( |
51
|
|
|
|
|
|
|
$request->method, |
52
|
|
|
|
|
|
|
$request->uri, |
53
|
|
|
|
|
|
|
\%options, |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |