line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Engine::Test::Request; |
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
302
|
use IO::Scalar; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
4
|
use URI; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
16
|
|
7
|
1
|
|
|
1
|
|
344
|
use URI::WithBase; |
|
1
|
|
|
|
|
620
|
|
|
1
|
|
|
|
|
20
|
|
8
|
1
|
|
|
1
|
|
4
|
use Scalar::Util 'blessed'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
320
|
use HTTP::Engine::Request; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use HTTP::Engine::RequestBuilder::NoEnv; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
|
|
|
|
|
|
my $class = shift; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
if ($_[0] && ref($_[0]) && $_[0]->isa('HTTP::Request')) { |
17
|
|
|
|
|
|
|
# create H::E::Req from HTTP::Request |
18
|
|
|
|
|
|
|
my $req = shift; |
19
|
|
|
|
|
|
|
my %args = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
return $class->build_request( |
22
|
|
|
|
|
|
|
$req->uri, |
23
|
|
|
|
|
|
|
$req->content, { |
24
|
|
|
|
|
|
|
headers => $req->headers, |
25
|
|
|
|
|
|
|
method => $req->method, |
26
|
|
|
|
|
|
|
protocol => $req->protocol, |
27
|
|
|
|
|
|
|
%args, |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} else { |
31
|
|
|
|
|
|
|
# create H::E::Req from hash |
32
|
|
|
|
|
|
|
my %args = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $body = delete $args{body} || ''; |
35
|
|
|
|
|
|
|
my $uri = delete $args{uri} or Carp::croak('missing uri'); |
36
|
|
|
|
|
|
|
my $method = delete $args{method} or Carp::croak('missing method'); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return $class->build_request( |
39
|
|
|
|
|
|
|
$uri, |
40
|
|
|
|
|
|
|
$body, { |
41
|
|
|
|
|
|
|
headers => +{}, |
42
|
|
|
|
|
|
|
protocol => undef, |
43
|
|
|
|
|
|
|
method => $method, |
44
|
|
|
|
|
|
|
%args |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub build_request { |
51
|
|
|
|
|
|
|
my ($class, $uri, $body, $args) = @_; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my %req_args = $class->build_request_args( |
54
|
|
|
|
|
|
|
$uri, |
55
|
|
|
|
|
|
|
$body, |
56
|
|
|
|
|
|
|
$args, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return HTTP::Engine::Request->new( |
60
|
|
|
|
|
|
|
request_builder => HTTP::Engine::RequestBuilder::NoEnv->new, |
61
|
|
|
|
|
|
|
%req_args, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# This method is used by Interface::Test. |
66
|
|
|
|
|
|
|
sub build_request_args { |
67
|
|
|
|
|
|
|
my($class, $uri, $body, $args) = @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
unless (blessed($uri) && $uri->isa('URI')) { |
70
|
|
|
|
|
|
|
$uri = URI->new( $uri ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return ( |
74
|
|
|
|
|
|
|
uri => URI::WithBase->new( $uri ), |
75
|
|
|
|
|
|
|
base => do { |
76
|
|
|
|
|
|
|
my $base = $uri->clone; |
77
|
|
|
|
|
|
|
$base->path_query('/'); |
78
|
|
|
|
|
|
|
$base; |
79
|
|
|
|
|
|
|
}, |
80
|
|
|
|
|
|
|
address => '127.0.0.1', |
81
|
|
|
|
|
|
|
port => '80', |
82
|
|
|
|
|
|
|
user => undef, |
83
|
|
|
|
|
|
|
_https_info => undef, |
84
|
|
|
|
|
|
|
_connection => { |
85
|
|
|
|
|
|
|
input_handle => IO::Scalar->new( \( $body ) ), |
86
|
|
|
|
|
|
|
env => ($args->{env} || {}), |
87
|
|
|
|
|
|
|
}, |
88
|
|
|
|
|
|
|
%$args, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |