Issues with Location: header in perl module
Igor Sysoev
is at rambler-co.ru
Tue May 12 09:28:25 MSD 2009
On Mon, May 11, 2009 at 01:54:02PM -0700, Michael Shadle wrote:
> trying to use nginx's built-in perl stuff... here's an example. any
> clue why this doesn't work?
>
> in /etc/nginx/nginx.conf:
>
> http {
> perl_modules /etc/nginx/perl/lib;
> perl_require Foo.pm;
> server {
> listen 80;
> server_name hostname.com;
>
> location / {
> perl Foo::handler;
> }
> }
> }
>
>
> in perl/lib/Foo.pm:
>
> package Foo;
> use nginx;
> sub handler
> {
>
> my $r = shift;
> $r->send_http_header("text/html");
>
> $r->header_out('Location', 'http://www.google.com/');
> return HTTP_MOVED_TEMPORARILY;
>
> }
>
> 1;
> __END__
>
> the Location: header is set but browser does not accept it. browser
> sits there indefinately. no infinite loop, just seems to sit there
> doing nothing
The headers should be set before $r->send_http_header().
Try
$r->header_out('Location', 'http://www.google.com/');
$r->send_http_header("text/html");
return OK;
or
$r->header_out('Location', 'http://www.google.com/');
return HTTP_MOVED_TEMPORARILY;
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list