line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::UserAgent::Proxy; |
2
|
54
|
|
|
54
|
|
67187
|
use Mojo::Base -base; |
|
54
|
|
|
|
|
136
|
|
|
54
|
|
|
|
|
408
|
|
3
|
|
|
|
|
|
|
|
4
|
54
|
|
|
54
|
|
19083
|
use Mojo::URL; |
|
54
|
|
|
|
|
170
|
|
|
54
|
|
|
|
|
505
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has [qw(http https not)]; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub detect { |
9
|
4
|
|
|
4
|
1
|
43
|
my $self = shift; |
10
|
4
|
|
100
|
|
|
35
|
$self->http($ENV{HTTP_PROXY} || $ENV{http_proxy}); |
11
|
4
|
|
100
|
|
|
39
|
$self->https($ENV{HTTPS_PROXY} || $ENV{https_proxy}); |
12
|
4
|
|
100
|
|
|
59
|
return $self->not([split /,/, $ENV{NO_PROXY} || $ENV{no_proxy} || '']); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub is_needed { |
16
|
956
|
|
100
|
956
|
1
|
1779
|
!grep { $_[1] =~ /\Q$_\E$/ } @{$_[0]->not // []}; |
|
35
|
|
|
|
|
395
|
|
|
956
|
|
|
|
|
2997
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub prepare { |
20
|
945
|
|
|
945
|
1
|
2503
|
my ($self, $tx) = @_; |
21
|
|
|
|
|
|
|
|
22
|
945
|
50
|
|
|
|
3027
|
$self->detect if $ENV{MOJO_PROXY}; |
23
|
945
|
|
|
|
|
2766
|
my $req = $tx->req; |
24
|
945
|
|
|
|
|
2970
|
my $url = $req->url; |
25
|
945
|
50
|
|
|
|
2638
|
return unless $self->is_needed($url->host); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# HTTP proxy |
28
|
945
|
|
|
|
|
3358
|
my $proto = $url->protocol; |
29
|
945
|
|
|
|
|
3284
|
my $http = $self->http; |
30
|
945
|
100
|
66
|
|
|
3003
|
$req->proxy(Mojo::URL->new($http)) if $http && $proto eq 'http'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# HTTPS proxy |
33
|
945
|
|
|
|
|
2608
|
my $https = $self->https; |
34
|
945
|
50
|
33
|
|
|
5640
|
$req->proxy(Mojo::URL->new($https)) if $https && $proto eq 'https'; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=encoding utf8 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Mojo::UserAgent::Proxy - User agent proxy manager |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SYNOPSIS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use Mojo::UserAgent::Proxy; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $proxy = Mojo::UserAgent::Proxy->new; |
50
|
|
|
|
|
|
|
$proxy->detect; |
51
|
|
|
|
|
|
|
say $proxy->http; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
L manages proxy servers for L. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
L implements the following attributes. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 http |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $http = $proxy->http; |
64
|
|
|
|
|
|
|
$proxy = $proxy->http('socks://sri:secret@127.0.0.1:8080'); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Proxy server to use for HTTP and WebSocket requests. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 https |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $https = $proxy->https; |
71
|
|
|
|
|
|
|
$proxy = $proxy->https('http://sri:secret@127.0.0.1:8080'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Proxy server to use for HTTPS and WebSocket requests. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 not |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $not = $proxy->not; |
78
|
|
|
|
|
|
|
$proxy = $proxy->not(['localhost', 'intranet.mojolicious.org']); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Domains that don't require a proxy server to be used. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
L inherits all methods from L and implements the following new ones. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 detect |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$proxy = $proxy->detect; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Check environment variables C, C, C, C, C and C |
91
|
|
|
|
|
|
|
for proxy information. Automatic proxy detection can be enabled with the C environment variable. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 is_needed |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $bool = $proxy->is_needed('intranet.example.com'); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Check if request for domain would use a proxy server. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 prepare |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$proxy->prepare(Mojo::Transaction::HTTP->new); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Prepare proxy server information for transaction. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SEE ALSO |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L, L, L. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |