`

使用Perl组建代理服务

    博客分类:
  • Perl
阅读更多

HTTP::Deamon是Perl中一个小server模块,我们可以使用此模块来组建一个处理HTTP的代理服务器。

一下是部分代码:

 

package Proxy;
use HTTP::Daemon;
use HTTP::Status;
use HTTP::Request;
use HTTP::Response;

my %setting = ( Localport => 8001);
my $deamon;

=cut
Constructor for proxy
=cut

sub new {
	&_init_deamon;
	my $this = {};
	bless $this;
	return $this;
}

=cut
Init the deamon ....
=cut

sub _init_deamon {
	print "init the deamon....\n";
	$deamon = HTTP::Daemon->new( LocalPort => $setting{Localport} );
}

=cut
Startup the proxy 
=cut

sub start {
	print "Startup the proxy...\n";
	print "Please contact me at: <URL:", $deamon->url, ">\n";
	while ( my $c = $deamon->accept ) {
		while ( my $r = $c->get_request ) {
			print $r->as_string;
			#$c->send_header( Content_type => "text/html" );
			#$c->send_response(content=>"this is a content");
			my $res = HTTP::Response->new;
			my $content = qq{
				<html>
				<head><title>this is a title</title></head>
				<body><h1>sssss</h1></body>
				</html>
			};
			$res->add_content($content);
			$c->send_response($res);
		}
		$c->close;
		undef($c);
	}
}



=cut
Push the filter method into.
=cut

sub pushFilter {
	print "filter";
}
1;
 
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics