line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Webrobot::MyUserAgent; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
6
|
use base "LWP::UserAgent"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1061
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# Author: Stefan Trcek |
7
|
|
|
|
|
|
|
# Copyright(c) 2004 ABAS Software AG |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
12
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
13
|
0
|
|
|
|
|
|
my $self = $class -> SUPER::new(); |
14
|
0
|
|
|
|
|
|
$self->{_basic_realm} = {}; |
15
|
0
|
|
|
|
|
|
$self->{obj_follow} = undef; |
16
|
0
|
|
|
|
|
|
bless ($self, $class); |
17
|
0
|
|
|
|
|
|
return $self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub client_302_bug { |
22
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
23
|
0
|
0
|
|
|
|
|
return $self->{_client_302_bug} if !@_; |
24
|
0
|
0
|
|
|
|
|
die "Can only set client_302_bug, can't unset" if !$_[0]; |
25
|
0
|
0
|
|
|
|
|
if (! $self->{_client_302_bug}) { |
26
|
0
|
|
|
|
|
|
$self->{_client_302_bug} = 1; |
27
|
0
|
|
|
|
|
|
push @{$self -> requests_redirectable}, 'POST'; |
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub set_basic_realm { |
32
|
0
|
|
|
0
|
1
|
|
my ($self, $realm) = @_; |
33
|
0
|
|
0
|
|
|
|
$self -> {_basic_realm} = $realm || {}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_basic_credentials { # INHERITED |
37
|
0
|
|
|
0
|
1
|
|
my ($self, $realm, $uri, $proxy) = @_; |
38
|
|
|
|
|
|
|
#print ">>REALM: $realm\nURI : $uri\n>>PROXY: $proxy\n"; |
39
|
0
|
|
|
|
|
|
my $ret = $self -> {_basic_realm} -> {$realm}; |
40
|
0
|
0
|
|
|
|
|
return $ret ? @$ret : undef; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub set_redirect_ok { |
44
|
0
|
|
|
0
|
1
|
|
my ($self, $recurse) = @_; |
45
|
0
|
|
|
|
|
|
return $self -> {obj_follow} = $recurse; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub clear_redirect_fail { |
49
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
50
|
0
|
|
|
|
|
|
$self -> {redirect_fail} = 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub is_redirect_fail { |
54
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
55
|
0
|
|
|
|
|
|
return $self -> {redirect_fail}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub redirect_ok { # INHERITED |
59
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
60
|
0
|
|
|
|
|
|
my ($r, $prev_response) = @_; |
61
|
|
|
|
|
|
|
# !!! Note that the interface of this function has changed in libwww-perl-5.76! |
62
|
|
|
|
|
|
|
# !!! Call SUPER in a generic way! |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# $r is of type HTTP::Request |
65
|
0
|
0
|
0
|
|
|
|
if ($self->client_302_bug && |
|
|
|
0
|
|
|
|
|
66
|
|
|
|
|
|
|
$r->method eq 'POST' && |
67
|
|
|
|
|
|
|
$r->content_type eq "application/x-www-form-urlencoded") { |
68
|
0
|
|
|
|
|
|
$r->method('GET'); |
69
|
0
|
|
|
|
|
|
$r->content(''); |
70
|
0
|
|
|
|
|
|
$r->remove_header('content-length'); |
71
|
0
|
|
|
|
|
|
$r->remove_header('content-type'); |
72
|
|
|
|
|
|
|
} |
73
|
0
|
0
|
|
|
|
|
return $self -> SUPER::redirect_ok(@_) if !defined $self -> {obj_follow}; |
74
|
0
|
0
|
|
|
|
|
$self -> {redirect_fail} = 1 if ! $self -> {obj_follow} -> allowed($r->{_uri}); |
75
|
0
|
|
|
|
|
|
return ! $self -> {redirect_fail}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub enable_referrer { |
79
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
80
|
0
|
0
|
|
|
|
|
$self->{_enable_referrer} = $value if defined $value; |
81
|
0
|
0
|
|
|
|
|
$self->{_referrer} = undef if ! $self->{_enable_referrer}; |
82
|
0
|
|
|
|
|
|
return $self->{_enable_referrer}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub referrer { |
86
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
87
|
0
|
0
|
0
|
|
|
|
$self->{_referrer} = $value if $self->{_enable_referrer} && defined $value; |
88
|
0
|
|
|
|
|
|
return $self->{_referrer}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
WWW::Webrobot::MyUserAgent - specialized user agent |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SYNOPSIS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $ua = WWW::Webrobot::MyUserAgent -> new |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DESCRIPTION |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This class inherits L. |
106
|
|
|
|
|
|
|
Additional features: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=over |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item basic authentification |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item aborting redirects |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 METHODS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item my $agent = WWW::Webrobot::MyUserAgent -> new |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Create user agent. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item $agent -> set_basic_realm ($realm) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Set a realm for basic authentification |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$realm = { |
130
|
|
|
|
|
|
|
"realm1" => ["login1", "password1"], |
131
|
|
|
|
|
|
|
"realm2" => ["login2", "password2"], |
132
|
|
|
|
|
|
|
}; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item $ua -> get_basic_credentials |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
inherited from L |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item $ua -> set_redirect_ok ($recurse) |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Set an object that allows recursion over the resulting responses. |
142
|
|
|
|
|
|
|
For C<$recurse> see L. |
143
|
|
|
|
|
|
|
I L. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item $ua -> clear_redirect_fail |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Clear the redirect_fail flag. |
148
|
|
|
|
|
|
|
This flag may be set in L. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item $ua -> is_redirect_fail |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Get the value of the redirect_fail flag. |
153
|
|
|
|
|
|
|
This flag indicates that a redirection was aborted. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item $ua -> redirect_ok |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
inherited from L |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item $ua -> client_302_bug |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$ua->client_302_bug(1) |
162
|
|
|
|
|
|
|
Behave like 302-buggy browser, no method to unset available. |
163
|
|
|
|
|
|
|
$ua->client_302_bug |
164
|
|
|
|
|
|
|
return whether value is set |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Most popular browsers don't implemenent HTTP response 302 correctly, |
167
|
|
|
|
|
|
|
see [RFC 2616] http://www.ietf.org/rfc/rfc2616.txt |
168
|
|
|
|
|
|
|
page 61, section 10.3.3, title "302 Found". In short: |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
- bug 1: browser redirects POST without user interaction |
171
|
|
|
|
|
|
|
- bug 2: browser changes method from POST to GET |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
You should better correct your server instead of using this method: |
174
|
|
|
|
|
|
|
return 303 instead of 302. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item $ua -> enable_referrer($value) |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Enable (1) or disable the HTTP referrer (which spells 'Referer') |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item $ua -> referrer($value) |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Set/get the referrer value if referrers have been enabled by enable_referrer. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |