line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite::Agent; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
90000
|
use strict; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
248
|
|
4
|
5
|
|
|
5
|
|
29
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
293
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
8878
|
use LWP::UserAgent; |
|
5
|
|
|
|
|
201538
|
|
|
5
|
|
|
|
|
107
|
|
7
|
5
|
|
|
5
|
|
1409
|
use List::MoreUtils; |
|
5
|
|
|
|
|
1864
|
|
|
5
|
|
|
|
|
2246
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
9
|
|
|
9
|
1
|
37
|
my ($class, $ua) = @_; |
11
|
9
|
|
33
|
|
|
100
|
my $self = bless { |
12
|
|
|
|
|
|
|
ua => $ua || LWP::UserAgent->new, |
13
|
|
|
|
|
|
|
}, $class; |
14
|
9
|
|
|
|
|
16219
|
return $self; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub agent { |
18
|
8
|
|
|
8
|
1
|
16
|
my ($self, $agent) = @_; |
19
|
8
|
|
|
|
|
41
|
$self->{ua}->agent($agent); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub request { |
23
|
0
|
|
|
0
|
1
|
0
|
my ($self, $req) = @_; |
24
|
0
|
|
|
|
|
0
|
$req = $self->filter_request($req); |
25
|
0
|
|
|
|
|
0
|
my $res = $self->{ua}->request($req); |
26
|
0
|
|
|
|
|
0
|
return $self->filter_response($res); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub filter_request { |
30
|
4
|
|
|
4
|
1
|
3137
|
my ($self, $req) = @_; |
31
|
4
|
|
100
|
|
|
46
|
my $accept_encoding = $req->header('Accept-Encoding') || ''; |
32
|
4
|
|
|
|
|
211
|
my @encodings = split(/\s*,\s*/, $accept_encoding); |
33
|
4
|
100
|
100
|
3
|
|
38
|
if (@encodings == 0 || List::MoreUtils::none { $_ eq 'gzip' } @encodings) { |
|
3
|
|
|
|
|
15
|
|
34
|
2
|
|
|
|
|
5
|
push(@encodings, 'gzip'); |
35
|
|
|
|
|
|
|
} |
36
|
4
|
|
|
|
|
23
|
$req->header('Accept-Encoding' => join(', ', @encodings)); |
37
|
4
|
|
|
|
|
255
|
return $req; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub filter_response { |
42
|
0
|
|
|
0
|
1
|
|
my ($self, $res) = @_; |
43
|
0
|
|
|
|
|
|
return $res; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
OAuth::Lite::Agent - default agent class |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 SYNOPSIS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$agent = OAuth::Lite::Agent->new; |
55
|
|
|
|
|
|
|
my $res = $agent->request($req); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Default user agent for OAuth::Lite::Consuemr. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 METHODS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 new |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
constructor. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
OAuth::Lite::Agent->new(); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
You can pass custom agent, that is required to implement |
70
|
|
|
|
|
|
|
'request' and 'agent' methods corresponding to the same named methods of LWP::UserAgnet. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $custom_agent = LWP::UserAgent->new(timeout => 10); |
73
|
|
|
|
|
|
|
OAuth::Lite::Agent->new($custom_agent); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 agent |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
agent setter |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$agent->agent("MyAgent/1.0.0"); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 request |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
As same as LWP::UserAgent, pass HTTP::Request object |
84
|
|
|
|
|
|
|
and returns HTTP::Response object. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$res = $agent->request($req); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 filter_request |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
filter the HTTP::Request object before request. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 filter_response |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
filter the HTTP::Response object after request. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SEE ALSO |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
http://oauth.pbwiki.com/ProblemReporting |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Lyo Kato, C |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
107
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
108
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|