App-PureProxy
view release on metacpan or search on metacpan
script/pureproxy.pl view on Meta::CPAN
INIT {
if ($^O eq 'darwin' && $ENV{OBJC_DISABLE_INITIALIZE_FORK_SAFETY} ne 'YES') {
$ENV{OBJC_DISABLE_INITIALIZE_FORK_SAFETY} = 'YES';
exec $^X, $0, @ARGV;
}
}
BEGIN {
*warnings::import = sub { };
}
use Config;
use constant SERVER => $ENV{PUREPROXY_SERVER}
|| $Config{useithreads} ? 'Thrall' : 'Starlight';
BEGIN {
delete $ENV{http_proxy};
delete $ENV{https_proxy};
}
use Plack::Builder;
use Plack::App::Proxy;
my $app = builder {
enable 'Proxy::Connect::IO';
enable 'Proxy::Requests';
Plack::App::Proxy->new(backend => 'HTTP::Tiny')->to_app;
};
use Plack;
use Plack::Runner;
my $runner = Plack::Runner->new(server => SERVER, env => 'proxy', loader => 'Plack::Loader', version_cb => \&version,);
sub _version () {
my $server = $runner->{server};
my $server_version
= eval { Plack::Util::load_class($server); $server->VERSION }
|| eval { Plack::Util::load_class("Plack::Handler::$server"); "Plack::Handler::$server"->VERSION }
|| 0;
return "PureProxy/$VERSION $server/$server_version Plack/" . Plack->VERSION . " Perl/$] ($^O)";
}
sub version {
my ($class) = @_;
print _version(), "\n";
}
$runner->parse_options('--max-workers=50', @ARGV);
if ($runner->{help}) {
require Pod::Usage;
Pod::Usage::pod2usage(-verbose => 99, -sections => "NAME|SYNOPSIS|DESCRIPTION|OPTIONS", -input => \*DATA);
}
my %options = @{ $runner->{options} };
if ($options{traffic_log}) {
my $body_eol = $options{traffic_log_body_eol};
if ($options{traffic_log} ne '1') {
open my $logfh, ">>", $options{traffic_log} or die "open($options{traffic_log}): $!";
$logfh->autoflush(1);
$app = builder {
enable 'TrafficLog',
logger => sub { $logfh->print(@_) },
body_eol => $body_eol,
with_body => !!$body_eol;
$app;
};
} else {
$app = builder { enable 'TrafficLog', body_eol => $body_eol, with_body => !!$body_eol; $app; };
}
}
if (not defined $runner->{access_log} or $runner->{access_log} eq '1') {
$runner->{access_log} = undef;
$app = builder { enable 'AccessLog'; $app; };
}
push @{ $runner->{options} }, 'server_software', _version();
$runner->run($app);
__DATA__
=head1 NAME
pureproxy - Pure Perl HTTP proxy server
=head1 SYNOPSIS
=for markdown ```sh
pureproxy --host=0.0.0.0 --port=5000 --workers=10 --server Starlight
pureproxy --traffic-log=traffic.log --traffic-log-body-eol='|'
pureproxy --access-log=access.log
pureproxy --other-plackup-options
pureproxy -v
http_proxy=http://localhost:5000/ lwp-request -m get http://www.perl.org/
https_proxy=http://localhost:5000/ lwp-request -m get https://metacpan.org/
=for markdown ```
=head1 DESCRIPTION
This is pure-Perl HTTP proxy server which can be run on almost every Perl
installation.
It uses L<thrall> pre-threading HTTP server if Perl supports threads or
L<starlight> pre-forking HTTP server otherwise.
It supports SSL and TLS if L<IO::Socket::SSL> is installed and IPv6 if
L<IO::Socket::IP> is installed.
It can be fat-packed and then run with any system with standard Perl
interpreter without installing other packages. See F<examples> directory for
fat-packed version of PureProxy script.
PureProxy is an application that accepts arguments of L<plackup> binary and
HTTP servers like L<thrall> or L<starlight>.
=cut
__END__
=head1 INSTALLATION
=head2 With cpanm(1)
=for markdown ```sh
cpanm App::PureProxy
=for markdown ```
=head2 Directly
=for markdown ```sh
lwp-request -m get https://raw.githubusercontent.com/dex4er/PureProxy/master/fatpack/install.sh | sh
=for markdown ```
or
=for markdown ```sh
curl -qsSL https://raw.githubusercontent.com/dex4er/PureProxy/master/fatpack/install.sh | sh
=for markdown ```
script/pureproxy.pl view on Meta::CPAN
directory changes. See L<plackup>. (default: none)
=head2 -R, --Reload
Makes plackup restart the server whenever a file in any of the given
directories changes. See L<plackup>. (default: none)
=head2 --socket
Enables UNIX socket support. The L<IO::Socket::UNIX> module is required. The
socket file has to be not yet created. The first character C<@> or C<\0> in
the socket file name means that an abstract socket address will be created.
(default: none)
=head2 --spawn-interval
If set, worker processes will not be spawned more than once every given
second. Also, when I<SIGHUP> is being received, no more than one worker
process will be collected every given second. This feature is useful for
doing a "slow restart". (default: none)
=head2 --ssl
Enables SSL support. The L<IO::Socket::SSL> module is required. (default: 0)
=head2 --ssl-ca-file
Specifies the path to the SSL CA certificate file which will be a part of
server's certificate chain. (default: none)
=head2 --ssl-cert-file
Specifies the path to the SSL certificate file. (default: none)
=head2 --ssl-client-ca-file
Specifies the path to the SSL CA certificate file for client verification.
(default: none)
=head2 --ssl-key-file
Specifies the path to the SSL key file. (default: none)
=head2 --ssl-verify-mode
Specifies the verification mode for the client certificate.
See L<IO::Socket::SSL/SSL_verify_mode> for details. (default: 0)
=head2 --timeout
Seconds until timeout. (default: 300)
=head2 --traffic-log
Enables L<Plack::Middleware::TrafficLog> middleware that logs detailed
information about headers and the body.
If the filename is providen then middleware writes to this file. Standard
output is used otherwise.
=head2 --traffic-log-body-eol
Sets the line separator for message's body for log generated by
L<Plack::Middleware::TrafficLog> middleware.
=head2 --umask
Changes file mode creation mask. The L<perlfunc/umask> is an octal number
representing disabled permissions bits for newly created files. It is usually
C<022> when a group shouldn't have permission to write or C<002> when a group
should have permission to write. (default: none)
=head2 --user
Changes the user id or user name that the server process should switch to
after binding to the port. The pid file, error log or unix socket also are
created before changing privileges. This option is usually used if the main
process is started with root privileges because binding to the low-numbered
(E<lt>1024) port. (default: none)
=head1 ENVIRONMENT
=head2 PUREPROXY_SERVER
Changes the default PSGI server. This is L<Thrall> if Perl supports threads
and L<Starlight> otherwise.
=head1 SEE ALSO
L<http://github.com/dex4er/PureProxy>.
=head1 BUGS
This tool has unstable features and can change in future.
=head1 AUTHOR
Piotr Roszatycki <dexter@cpan.org>
=head1 LICENSE
Copyright (c) 2014-2015, 2023-2024 Piotr Roszatycki <dexter@cpan.org>.
This is free software; you can redistribute it and/or modify it under
the same terms as perl itself.
See L<http://dev.perl.org/licenses/artistic.html>
( run in 1.230 second using v1.01-cache-2.11-cpan-98e64b0badf )