line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Proxy::Requests; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Plack::Middleware::Proxy::Requests - Forward proxy server |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=for markdown ```perl |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# In app.psgi |
12
|
|
|
|
|
|
|
use Plack::Builder; |
13
|
|
|
|
|
|
|
use Plack::App::Proxy; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
builder { |
16
|
|
|
|
|
|
|
enable "Proxy::Connect"; |
17
|
|
|
|
|
|
|
enable "Proxy::AddVia"; |
18
|
|
|
|
|
|
|
enable "Proxy::Requests"; |
19
|
|
|
|
|
|
|
Plack::App::Proxy->new->to_app; |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=for markdown ``` |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=for markdown ```sh |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# From shell |
27
|
|
|
|
|
|
|
plackup -s Twiggy -E Proxy -e 'enable q{AccessLog}' app.psgi |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# or |
30
|
|
|
|
|
|
|
twiggy -MPlack::App::Proxy \ |
31
|
|
|
|
|
|
|
-e 'enable q{AccessLog}; enable q{Proxy::Connect}; \ |
32
|
|
|
|
|
|
|
enable q{Proxy::AddVia}; enable q{Proxy::Requests}; \ |
33
|
|
|
|
|
|
|
Plack::App::Proxy->new->to_app' |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=for markdown ``` |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This module handles HTTP requests as a forward proxy server. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Its job is to set a C environment variable based on |
42
|
|
|
|
|
|
|
C variable. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
The HTTP responses from the Internet might be invalid. In that case it |
45
|
|
|
|
|
|
|
is required to run the server without L module. |
46
|
|
|
|
|
|
|
This module is started by default and disabled if C<-E> or |
47
|
|
|
|
|
|
|
C<--no-default-middleware> option is used when starting L |
48
|
|
|
|
|
|
|
script. Note that this disables also L so |
49
|
|
|
|
|
|
|
it has to be enabled explicitly if needed. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
The default server L alias C can hang |
52
|
|
|
|
|
|
|
up on the stalled connection. It is better to run a proxy server with |
53
|
|
|
|
|
|
|
L, L or L. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=for readme stop |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
2
|
|
72811
|
use 5.006; |
|
2
|
|
|
|
|
9
|
|
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
39
|
|
62
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
106
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
our $VERSION = '0.0104'; |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
2
|
|
505
|
use parent qw(Plack::Middleware); |
|
2
|
|
|
|
|
307
|
|
|
2
|
|
|
|
|
10
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub call { |
69
|
1
|
|
|
1
|
1
|
107
|
my ($self, $env) = @_; |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
3
|
$env->{'plack.proxy.url'} = $env->{REQUEST_URI}; |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
4
|
return $self->app->($env); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
__END__ |