line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::UserAgent::Proxy; |
2
|
54
|
|
|
54
|
|
64263
|
use Mojo::Base -base; |
|
54
|
|
|
|
|
138
|
|
|
54
|
|
|
|
|
379
|
|
3
|
|
|
|
|
|
|
|
4
|
54
|
|
|
54
|
|
18169
|
use Mojo::URL; |
|
54
|
|
|
|
|
152
|
|
|
54
|
|
|
|
|
433
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has [qw(http https not)]; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub detect { |
9
|
4
|
|
|
4
|
1
|
45
|
my $self = shift; |
10
|
4
|
|
100
|
|
|
38
|
$self->http($ENV{HTTP_PROXY} || $ENV{http_proxy}); |
11
|
4
|
|
100
|
|
|
46
|
$self->https($ENV{HTTPS_PROXY} || $ENV{https_proxy}); |
12
|
4
|
|
100
|
|
|
60
|
return $self->not([split /,/, $ENV{NO_PROXY} || $ENV{no_proxy} || '']); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub is_needed { |
16
|
956
|
|
100
|
956
|
1
|
1683
|
!grep { $_[1] =~ /\Q$_\E$/ } @{$_[0]->not // []}; |
|
35
|
|
|
|
|
374
|
|
|
956
|
|
|
|
|
2868
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub prepare { |
20
|
945
|
|
|
945
|
1
|
2433
|
my ($self, $tx) = @_; |
21
|
|
|
|
|
|
|
|
22
|
945
|
50
|
|
|
|
2810
|
$self->detect if $ENV{MOJO_PROXY}; |
23
|
945
|
|
|
|
|
2682
|
my $req = $tx->req; |
24
|
945
|
|
|
|
|
2797
|
my $url = $req->url; |
25
|
945
|
50
|
|
|
|
2632
|
return unless $self->is_needed($url->host); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# HTTP proxy |
28
|
945
|
|
|
|
|
3206
|
my $proto = $url->protocol; |
29
|
945
|
|
|
|
|
2955
|
my $http = $self->http; |
30
|
945
|
100
|
66
|
|
|
2883
|
$req->proxy(Mojo::URL->new($http)) if $http && $proto eq 'http'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# HTTPS proxy |
33
|
945
|
|
|
|
|
2469
|
my $https = $self->https; |
34
|
945
|
50
|
33
|
|
|
5318
|
$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 |