App-HTTP_Proxy_IMP
view release on metacpan or search on metacpan
lib/App/HTTP_Proxy_IMP/IMP.pm view on Meta::CPAN
use strict;
use warnings;
package App::HTTP_Proxy_IMP::IMP;
use Net::Inspect::Debug qw(:DEFAULT $DEBUG);
use Net::IMP::Debug var => \$DEBUG, sub => \&debug;
use Net::IMP qw(:DEFAULT :log);
use Net::IMP::HTTP;
use Scalar::Util 'weaken';
use Hash::Util 'lock_ref_keys';
use Compress::Raw::Zlib;
no warnings 'experimental'; # smartmatch
use Carp;
my %METHODS_RFC2616 = map { ($_,1) } qw( GET HEAD POST PUT DELETE OPTIONS CONNECT TRACE );
my %METHODS_WITHOUT_RQBODY = map { ($_,1) } qw( GET HEAD DELETE CONNECT );
my %METHODS_WITH_RQBODY = map { ($_,1) } qw( POST PUT );
my %CODE_WITHOUT_RPBODY = map { ($_,1) } qw(204 205 304);
my %METHODS_WITHOUT_RPBODY = map { ($_,1) } qw(HEAD);
# we want plugins to suppport the HTTP Request innterface
my $interface = [
IMP_DATA_HTTPRQ,
[
IMP_PASS,
IMP_PREPASS,
IMP_REPLACE,
IMP_TOSENDER,
IMP_DENY,
IMP_LOG,
IMP_ACCTFIELD,
IMP_PAUSE,
IMP_CONTINUE,
IMP_FATAL,
]
];
sub can_modify {
return shift->{can_modify};
}
# create a new factory object
sub new_factory {
my ($class,%args) = @_;
my @factory;
for my $module (@{ delete $args{mod} || [] }) {
if ( ref($module)) {
# assume it is already an IMP factory object
push @factory, $module;
next;
}
# --filter mod=args
my ($mod,$args) = $module =~m{^([a-z][\w:]*)(?:=(.*))?$}i
or die "invalid module $module";
eval "require $mod" or die "cannot load $mod args=$args: $@";
my %args = $mod->str2cfg($args//'');
my $factory = $mod->new_factory(%args)
or croak("cannot create Net::IMP factory for $mod");
$factory =
$factory->get_interface( $interface ) &&
$factory->set_interface( $interface )
or croak("$mod does not implement the interface supported by us");
push @factory,$factory;
}
@factory or return;
if (@factory>1) {
# for cascading filters we need Net::IMP::Cascade
require Net::IMP::Cascade;
my $cascade = Net::IMP::Cascade->new_factory( parts => [ @factory ])
or croak("cannot create Net::IMP::Cascade factory");
$cascade = $cascade->set_interface( $interface ) or
croak("cascade does not implement the interface supported by us");
@factory = $cascade;
}
my $factory = $factory[0];
( run in 0.924 second using v1.01-cache-2.11-cpan-39bf76dae61 )