2012-11-26 163 views
1

我正在开发一个Web应用程序,我想知道是否有方法或某种模块可以拦截或处理任何HTTP请求,然后才能显示给客户端。我无法修改httpd.conf文件,因此它不是一个选项。 我想通过拒绝访问或重定向到其他页面或通过修改发送给客户端和其他某些东西的响应来为我的Web应用程序添加一些安全性。 我也听说过请求调度,也许它可以帮助我。有人知道如何做到这一点?如何拦截Perl中的HTTP请求?

+3

您必须提供更多信息:哪些框架/模块;它是如何工作的(cgi/fastcgi/mod_perl);如何将响应发送到客户端等 – PSIAlt

+0

我只想知道拦截HTTP请求的方法,就这些。我使用的是mod_perl,但我无法对其进行任何更改,而且我也没有使用任何框架。 – ChuyAMS

+1

如果您使用的是mod_perl,那么您可以完全访问Apache请求生命周期。 http://perl.apache.org/docs/2.0/user/handlers/http.html –

回答

3

也许你可以使用Plack::Handler::Apache2启用PSGI支持。从那里,你可以使用PSGI中间件模块来修改请求和响应。

如果不知道如何在您的mod_perl环境中执行Perl的设置,就很难获得更具体的内容。

2

你可能想看看HTTP::Proxy,一个perl模块编写一个Web代理...这样的例子:

# alternate initialisation 
    my $proxy = HTTP::Proxy->new; 
    $proxy->port(3128); # the classical accessors are here! 

    # this is a MainLoop-like method 
    $proxy->start; 
    my $d = HTTP::Daemon->new || die; 
    while (my $c = $d->accept) { 
     while (my $r = $c->get_request) { 
      if ($r->method eq 'GET' and $r->uri->path eq "/xyzzy") { 
       # remember, this is *not* recommended practice :-) 
       $c->send_file_response("/home/hd1/.zshrc"); 
      } 
      else { 
       $c->send_error(RC_FORBIDDEN) 
      } 
     } 
     $c->close; 
     undef($c); 
    }