| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::ProxyThat; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# DATE |
|
4
|
|
|
|
|
|
|
# VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
13
|
|
|
13
|
|
224367
|
use strict; |
|
|
13
|
|
|
|
|
39
|
|
|
|
13
|
|
|
|
|
325
|
|
|
7
|
13
|
|
|
13
|
|
39
|
use warnings; |
|
|
13
|
|
|
|
|
26
|
|
|
|
13
|
|
|
|
|
299
|
|
|
8
|
13
|
|
|
13
|
|
8151
|
use Getopt::Long qw(:config pass_through); |
|
|
13
|
|
|
|
|
113373
|
|
|
|
13
|
|
|
|
|
52
|
|
|
9
|
13
|
|
|
13
|
|
8229
|
use Pod::Usage; |
|
|
13
|
|
|
|
|
604500
|
|
|
|
13
|
|
|
|
|
1677
|
|
|
10
|
13
|
|
|
13
|
|
7228
|
use Plack::App::Proxy; |
|
|
13
|
|
|
|
|
767468
|
|
|
|
13
|
|
|
|
|
442
|
|
|
11
|
13
|
|
|
13
|
|
5486
|
use Plack::Builder; |
|
|
13
|
|
|
|
|
45279
|
|
|
|
13
|
|
|
|
|
988
|
|
|
12
|
13
|
|
|
13
|
|
91
|
use Plack::Runner; |
|
|
13
|
|
|
|
|
26
|
|
|
|
13
|
|
|
|
|
260
|
|
|
13
|
13
|
|
|
13
|
|
5551
|
use File::chdir; |
|
|
13
|
|
|
|
|
39364
|
|
|
|
13
|
|
|
|
|
7033
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
|
16
|
6
|
|
|
6
|
1
|
16122
|
my $class = shift; |
|
17
|
6
|
|
|
|
|
468
|
my $self = bless { port => 3080 }, $class; |
|
18
|
|
|
|
|
|
|
|
|
19
|
6
|
50
|
|
|
|
360
|
GetOptions( $self, "help", "man", "port=i", "ssl" ) || pod2usage(2); |
|
20
|
6
|
50
|
|
|
|
8016
|
pod2usage(1) if $self->{help}; |
|
21
|
6
|
50
|
|
|
|
126
|
pod2usage( -verbose => 2 ) if $self->{man}; |
|
22
|
|
|
|
|
|
|
|
|
23
|
6
|
50
|
|
|
|
150
|
$self->{url} = $ARGV[0] |
|
24
|
|
|
|
|
|
|
or pod2usage(2); |
|
25
|
|
|
|
|
|
|
|
|
26
|
6
|
50
|
|
|
|
108
|
if ( $self->{ssl} ) { |
|
27
|
0
|
|
|
|
|
0
|
require AppLib::CreateSelfSignedSSLCert; |
|
28
|
0
|
|
|
|
|
0
|
require File::Temp; |
|
29
|
0
|
|
|
|
|
0
|
my $dir = File::Temp::tempdir( CLEANUP => 1 ); |
|
30
|
0
|
|
|
|
|
0
|
local $CWD = $dir; |
|
31
|
0
|
|
|
|
|
0
|
my $res = AppLib::CreateSelfSignedSSLCert::create_self_signed_ssl_cert( |
|
32
|
|
|
|
|
|
|
hostname => 'localhost', |
|
33
|
|
|
|
|
|
|
interactive => 0, |
|
34
|
|
|
|
|
|
|
); |
|
35
|
0
|
0
|
|
|
|
0
|
die "Can't create self-signed SSL certificate: $res->[0] - $res->[1]" |
|
36
|
|
|
|
|
|
|
unless $res->[0] == 200; |
|
37
|
0
|
|
|
|
|
0
|
$self->{'ssl-cert'} = "$dir/localhost.crt"; |
|
38
|
0
|
|
|
|
|
0
|
$self->{'ssl-key'} = "$dir/localhost.key"; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
6
|
|
|
|
|
126
|
return $self; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub run { |
|
45
|
6
|
|
|
6
|
1
|
66
|
my ($self) = @_; |
|
46
|
6
|
|
|
|
|
534
|
my $runner = Plack::Runner->new; |
|
47
|
|
|
|
|
|
|
$runner->parse_options( |
|
48
|
|
|
|
|
|
|
'--server' => 'Starman', |
|
49
|
|
|
|
|
|
|
'--port' => $self->{port}, |
|
50
|
|
|
|
|
|
|
'--env' => 'production', |
|
51
|
|
|
|
|
|
|
( |
|
52
|
|
|
|
|
|
|
$self->{ssl} |
|
53
|
|
|
|
|
|
|
? ( |
|
54
|
|
|
|
|
|
|
'--enable-ssl', |
|
55
|
|
|
|
|
|
|
'--ssl-cert' => $self->{'ssl-cert'}, |
|
56
|
|
|
|
|
|
|
'--ssl-key' => $self->{'ssl-key'}, |
|
57
|
|
|
|
|
|
|
) |
|
58
|
|
|
|
|
|
|
: () |
|
59
|
|
|
|
|
|
|
), |
|
60
|
6
|
|
|
6
|
|
358416
|
'--server_ready' => sub { $self->_server_ready(@_) }, |
|
61
|
6
|
50
|
|
|
|
714
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
6
|
|
|
|
|
13692
|
eval { |
|
64
|
|
|
|
|
|
|
$runner->run( |
|
65
|
|
|
|
|
|
|
Plack::App::Proxy->new( |
|
66
|
|
|
|
|
|
|
remote => $self->{url}, |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#backend => 'LWP' ## TODO as arg |
|
69
|
6
|
|
|
|
|
594
|
)->to_app |
|
70
|
|
|
|
|
|
|
); |
|
71
|
|
|
|
|
|
|
}; |
|
72
|
0
|
0
|
|
|
|
0
|
if ( my $e = $@ ) { |
|
73
|
0
|
0
|
|
|
|
0
|
die "FATAL: port $self->{port} is already in use, try another one\n" |
|
74
|
|
|
|
|
|
|
if $e =~ m/failed to listen to port/; |
|
75
|
0
|
|
|
|
|
0
|
die "FATAL: internal error - $e\n"; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _server_ready { |
|
81
|
6
|
|
|
6
|
|
30
|
my ( $self, $args ) = @_; |
|
82
|
|
|
|
|
|
|
|
|
83
|
6
|
|
50
|
|
|
30
|
my $host = $args->{host} || '127.0.0.1'; |
|
84
|
6
|
|
50
|
|
|
108
|
my $proto = $args->{proto} || 'http'; |
|
85
|
6
|
|
|
|
|
12
|
my $port = $args->{port}; |
|
86
|
|
|
|
|
|
|
|
|
87
|
6
|
|
|
|
|
276
|
print "Providing a proxy for '$self->{'url'}' at:\n"; |
|
88
|
6
|
|
|
|
|
78
|
print " $proto://$host:$port/\n"; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# ABSTRACT: Proxy an URL from the command line |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |