Нарыл скрипт перлового прокси, решил его немного доработать под себя, чтобы все время не вводить юзер агент ручками, пусть значения берутся из файла... Но почему то вся моя затея не привела ни к чему хорошему, скрипт не пашет, две недели ломаю голову, ткните мну, где нужно поправить код, истинные знатоки перла...
Код:
#!/usr/bin/perl
use HTTP::Daemon;
use LWP::UserAgent;
use Compress::Zlib;
use CGI::Carp qw(fatalsToBrowser);
my @ext = qw(x-gtar x-gzip x-tar zip image zip z gz tz taz tgz lzh arj arc tar cab wmz yfs wsz exe uu xxe bhx b64 hqx mim);
my $port = 8080;
$SIG{PIPE} = 'IGNORE';
my $server = HTTP::Daemon->new( LocalPort => $port ) or
die "Can't start server ($@)" unless defined $server;
while (my $conn = $server->accept) {
my $ua = LWP::UserAgent->new;
my $str = do {my $fh = open "<filename.txt"; local $/ = undef; <$fh>};
chomp $str;
$ua->default_header('My header' => $str);}
while (my $conn = $server->accept) {
while (my $request = $conn->get_request) {
$conn->autoflush;
$request -> remove_header('Proxy-Connection');
$request -> remove_header('Keep-Alive');
$request -> header(Connection=>'close');
my $resp = $ua->simple_request($request);
my $c_cont = $resp->content;
if ( $resp->content_encoding || (grep { $_ =~ /$resp->content_type/g } @ext) || length($c_cont) < 3000 ) {
$conn->send_response($resp);
}
else {
$c_cont_zip = Compress::Zlib::memGzip($c_cont);
$resp->content($c_cont_zip);
$resp->content_encoding('gzip');
$conn->send_response($resp);
}
}
print STDERR "Close: ", $conn->reason, "\n";
$conn->close;
undef $conn;
}