App-HTTP_Proxy_IMP
view release on metacpan or search on metacpan
lib/App/HTTP_Proxy_IMP.pm view on Meta::CPAN
-d|--debug [RX] debug mode, if RX is given restricts debugging to packages
matching RX
-T|--trace T enable Net::Inspect traces
Examples:
start proxy at 127.0.0.1:8888 and log all requests to /tmp as pcap files
$cmd --filter Net::IMP::SessionLog=dir=/tmp/&format=pcap 127.0.0.1:8888
start proxy at 127.0.0.1:8888 and log all form fields
$cmd --filter LogFormData 127.0.0.1:8888
start proxy at 127.0.0.1:8888 with CSRF protection plugin
$cmd --filter CSRFprotect 127.0.0.1:8888
start proxy at 127.0.0.1:8888 with CSRF protection plugin, using upstream
proxy proxy:8888
$cmd --filter CSRFprotect 127.0.0.1:8888=proxy:8888
USAGE
exit(2);
}
############################################################################
# AnyEvent wrapper to privide Net::IMP::Remote etc with acccess to
# IO events
############################################################################
package App::HTTP_Proxy_IMP::EventLoop;
sub new { bless {},shift }
{
my %watchr;
sub onread {
my ($self,$fh,$cb) = @_;
defined( my $fn = fileno($fh)) or die "invalid filehandle";
if ( $cb ) {
$watchr{$fn} = AnyEvent->io(
fh => $fh,
cb => $cb,
poll => 'r'
);
} else {
undef $watchr{$fn};
}
}
}
{
my %watchw;
sub onwrite {
my ($self,$fh,$cb) = @_;
defined( my $fn = fileno($fh)) or die "invalid filehandle";
if ( $cb ) {
$watchw{$fn} = AnyEvent->io(
fh => $fh,
cb => $cb,
poll => 'w'
);
} else {
undef $watchw{$fn};
}
}
}
sub now { return AnyEvent->now }
sub timer {
my ($self,$after,$cb,$interval) = @_;
return AnyEvent->timer(
after => $after,
cb => $cb,
$interval ? ( interval => $interval ):()
);
}
1;
__END__
=head1 NAME
App::HTTP_Proxy_IMP - HTTP proxy with the ability to inspect and modify content
=head1 SYNOPSIS
# only use cmdline args
App::HTTP_Proxy_IMP->new(@ARGV)->start;
# only use given args
App::HTTP_Proxy_IMP->new(\%options)->start;
# combine cmdline args with given defaults
App::HTTP_Proxy_IMP->new(\%options,@ARGV)->start;
# short for App::HTTP_Proxy_IMP->new(...)->start;
App::HTTP_Proxy_IMP->start(...);
# show cmdline usage
App::HTTP_Proxy_IMP->usage();
=head1 DESCRIPTION
App::HTTP_Proxy_IMP implements an HTTP proxy, which can inspect and modify the
HTTP header or content before forwarding. Inspection and modification is done
with plugins implementing the L<Net::IMP> interface.
The proxy is single-threaded and non-forking, but due to the event-driven model
it can still process multiple connections in parallel. It is mainly intended to
be used as a platform for easy prototyping of interesting ideas using IMP
plugins, but should be also fast enough to be used to enhance, secure, restrict
or protocol the browsing experience for small groups.
=head2 Public Methods
=over 4
=item * new([\%OPTIONS],[@ARGV])
Creates a new object.
The first argument might be an hash reference with options.
All other arguments will be used as ARGV for cmdline parsing and might result in
overwriting the defaults from OPTIONS.
The following options and its matching cmdline arguments are defined:
=over 8
=item filter ARRAY | -F|--filter mod
( run in 0.794 second using v1.01-cache-2.11-cpan-02777c243ea )