line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::HTTP::Client::Fusion; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
27993276
|
use strict; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
305
|
|
4
|
8
|
|
|
8
|
|
68
|
use warnings; |
|
8
|
|
|
|
|
34
|
|
|
8
|
|
|
|
|
369
|
|
5
|
8
|
|
|
8
|
|
45
|
use base 'FusionInventory::Agent::HTTP::Client'; |
|
8
|
|
|
|
|
123
|
|
|
8
|
|
|
|
|
3910
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
3105
|
use JSON; |
|
8
|
|
|
|
|
37970
|
|
|
8
|
|
|
|
|
124
|
|
8
|
8
|
|
|
8
|
|
1214
|
use HTTP::Request; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
80
|
|
9
|
8
|
|
|
8
|
|
185
|
use HTTP::Headers; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
89
|
|
10
|
8
|
|
|
8
|
|
6878
|
use HTTP::Cookies; |
|
8
|
|
|
|
|
59701
|
|
|
8
|
|
|
|
|
87
|
|
11
|
8
|
|
|
8
|
|
247
|
use URI::Escape; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
6210
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
20
|
|
|
20
|
1
|
143
|
my ($class, %params) = @_; |
15
|
|
|
|
|
|
|
|
16
|
20
|
|
|
|
|
116
|
my $self = $class->SUPER::new(%params); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Stack the messages sent in order to be able to check the |
19
|
|
|
|
|
|
|
# correctness of the behavior with the test-suite |
20
|
20
|
50
|
|
|
|
71
|
if ($params{debug}) { |
21
|
0
|
|
|
|
|
0
|
$self->{debug} = 1; |
22
|
0
|
|
|
|
|
0
|
$self->{msgStack} = [] |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
20
|
|
|
|
|
78
|
$self->{_cookies} = HTTP::Cookies->new ; |
26
|
|
|
|
|
|
|
|
27
|
20
|
|
|
|
|
364
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _prepareVal { |
31
|
0
|
|
|
0
|
|
|
my ($self, $val) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
return '' unless length($val); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# forbid to long argument. |
36
|
0
|
|
|
|
|
|
while (length(URI::Escape::uri_escape_utf8($val)) > 1500) { |
37
|
0
|
|
|
|
|
|
$val =~ s/^.{5}/…/; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return URI::Escape::uri_escape_utf8($val); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub send { ## no critic (ProhibitBuiltinHomonyms) |
44
|
0
|
|
|
0
|
1
|
|
my ($self, %params) = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
push @{$self->{msgStack}}, $params{args} if $self->{debug}; |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $url = ref $params{url} eq 'URI' ? |
49
|
0
|
0
|
|
|
|
|
$params{url} : URI->new($params{url}); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $method = (exists($params{method}) && $params{method} =~ /^GET|POST$/) ? |
52
|
0
|
0
|
0
|
|
|
|
$params{method} : 'GET' ; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $urlparams = 'action='.uri_escape($params{args}->{action}); |
55
|
0
|
|
|
|
|
|
my $referer = ''; |
56
|
0
|
0
|
|
|
|
|
if ($method eq 'POST') { |
57
|
0
|
|
|
|
|
|
$referer = $url; |
58
|
0
|
|
|
|
|
|
$url .= '?'.$urlparams ; |
59
|
0
|
0
|
|
|
|
|
$url .= '&uuid='.uri_escape($params{args}->{uuid}) if (exists($params{args}->{uuid})); |
60
|
0
|
|
|
|
|
|
$url .= '&method=POST' ; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
foreach my $k (keys %{$params{args}}) { |
|
0
|
|
|
|
|
|
|
64
|
0
|
0
|
0
|
|
|
|
if (ref($params{args}->{$k}) eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
foreach (@{$params{args}->{$k}}) { |
|
0
|
|
|
|
|
|
|
66
|
0
|
|
0
|
|
|
|
$urlparams .= '&'.$k.'[]='.$self->_prepareVal($_ || ''); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} elsif (ref($params{args}->{$k}) eq 'HASH') { |
69
|
0
|
|
|
|
|
|
foreach (keys %{$params{args}->{$k}}) { |
|
0
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$urlparams .= '&'.$k.'['.$_.']='.$self->_prepareVal($params{args}->{$k}{$_}); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} elsif ($k ne 'action' && length($params{args}->{$k})) { |
73
|
0
|
|
|
|
|
|
$urlparams .= '&'.$k.'='.$self->_prepareVal($params{args}->{$k}); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
$url .= '?'.$urlparams if ($method eq 'GET'); |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
$self->{logger}->debug2($url) if $self->{logger}; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $request ; |
82
|
0
|
0
|
|
|
|
|
if ($method eq 'GET') { |
83
|
0
|
|
|
|
|
|
$request = HTTP::Request->new($method => $url); |
84
|
|
|
|
|
|
|
} else { |
85
|
0
|
0
|
|
|
|
|
$self->{logger}->debug2("POST: ".$urlparams) if $self->{logger}; |
86
|
0
|
|
|
|
|
|
my $headers = HTTP::Headers->new( |
87
|
|
|
|
|
|
|
'Content-Type' => 'application/x-www-form-urlencoded', |
88
|
|
|
|
|
|
|
'Referer' => $referer |
89
|
|
|
|
|
|
|
); |
90
|
0
|
|
|
|
|
|
$request = HTTP::Request->new( |
91
|
|
|
|
|
|
|
$method => $url, |
92
|
|
|
|
|
|
|
$headers, |
93
|
|
|
|
|
|
|
$urlparams |
94
|
|
|
|
|
|
|
); |
95
|
0
|
|
|
|
|
|
$self->{_cookies}->add_cookie_header( $request ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $response = $self->request($request); |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
return unless $response; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
$self->{_cookies}->extract_cookies($response); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
return eval { from_json( $response->content(), { utf8 => 1 } ) }; |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
__END__ |