我不想使用HTTP :: Proxy包,因为我想要转储几个请求.我的一个班轮看起来像这样,但在试图传递标题时打破了:
perl -MData::Dumper -MHTTP::Daemon -MHTTP::Status -MLWP::UserAgent -e 'my $ua = LWP::UserAgent->new;my $d=new HTTP::Daemon(LocalPort=>1999);print "Please contact me at: <", $d->url, ">\n";while (my $c = $d->accept) {while (my $r = $c->get_request) {if ($r->method eq 'GET' and $r->url->path eq "/uploader") {$c->send_response("whatever.");print Dumper($r);}else{$response=$ua->request($r->method,"http://localhost:1996".$r->uri,$r->headers,$r->content);$c->send_response($response);}}}'
格式化,那是:
#perl -e ' use Data::Dumper; use HTTP::Daemon; use HTTP::Status; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $d=new HTTP::Daemon(LocalPort=>1999); print "Please contact me at: < ", $d->url, " >\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { if ($r->method eq 'GET' and $r->url->path eq "/uploaded") { $c->send_response("whatever."); print Dumper($r); } else { $response = $ua -> request( $r->method, "http://localhost:1996" . $r->uri, $r->headers, $r->content); $c->send_response($response); } } }#'
所以我不能只是传入请求,因为我需要更改主机,而且我不能只是传入标题......所以我应该怎么做才能保持简短.
那么有谁能让这个更好的单线程?
哎呀,我修好了这个:
#perl -e ' use Data::Dumper; use HTTP::Daemon; use HTTP::Status; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $d=new HTTP::Daemon(LocalPort=>1999); print "Please contact me at: < ", $d->url, " >\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { if ($r->method eq "GET" and $r->url->path eq "/uploaded") { $c->send_response("whatever."); print Dumper($r); } else { $response = $ua -> request( HTTP::Request->new( $r->method, "http://localhost:1996" . $r->uri, $r->headers, $r->content)); $c->send_response($response); } } }#'
注意HTTP::Request->new
是的...所以它有效,它有点慢.但那没关系