Issues with Location: header in perl module

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

2009/05/11 13:29:42 [debug] 2761#0: *1 write new buf t:1 f:0
000000000E912518, pos 000000000E912518, size: 205 file: 0, size: 0
2009/05/11 13:29:42 [debug] 2761#0: *1 http write filter: l:0 f:0 s:205
2009/05/11 13:29:42 [debug] 2761#0: *1 perl sv2str: 04840304 “Location”
2009/05/11 13:29:42 [debug] 2761#0: *1 perl sv2str: 04840304
http://www.google.com
2009/05/11 13:29:42 [debug] 2761#0: *1 call_sv: 302
2009/05/11 13:29:42 [debug] 2761#0: *1 perl handler done: 302
2009/05/11 13:29:42 [debug] 2761#0: *1 http finalize request: 302, “/?”
1
2009/05/11 13:29:42 [debug] 2761#0: *1 http special response: 302, “/?”
2009/05/11 13:29:42 [debug] 2761#0: *1 http set discard body
2009/05/11 13:29:42 [debug] 2761#0: *1 xslt filter header
2009/05/11 13:29:42 [debug] 2761#0: *1 HTTP/1.1 302 Moved Temporarily^M
Server: nginx^M
Date: Mon, 11 May 2009 20:29:42 GMT^M
Content-Type: text/html; charset=utf-8^M
Content-Length: 154^M
Transfer-Encoding: chunked^M
Connection: close^M
Vary: Accept-Encoding^M
Content-Encoding: gzip^M
Location: http://www.google.com^M

2009/05/11 13:29:42 [debug] 2761#0: *1 write old buf t:1 f:0
000000000E912518, pos 000000000E912518, size: 205 file: 0, size: 0
2009/05/11 13:29:42 [debug] 2761#0: *1 write new buf t:1 f:0
000000000E912648, pos 000000000E912648, size: 274 file: 0, size: 0
2009/05/11 13:29:42 [debug] 2761#0: *1 http write filter: l:0 f:0 s:479
2009/05/11 13:29:42 [debug] 2761#0: *1 malloc: 000000000E90BA90:4096

I think header_out should appear before send_http_header.

On Mon, May 11, 2009 at 01:54:02PM -0700, Michael S. wrote:

             server_name hostname.com;

package Foo;
}

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;

先把perl编译进nginx中。perl_modules是路径,perl_require是调用的文件
è¿™ä¸ªç¤ºä¾‹æ²¡ä»€ä¹ˆç”¨å•Šï¼Œä½ è¦å®žçŽ°ä»€ä¹ˆåŠŸèƒ½ï¼Ÿ
nginx里perl的用法和*nix下的没多大区别,稍作修改就可以用了

Posted at Nginx Forum:

I tried Google to translate this but I can’t understand it still…

English please? :slight_smile:

2009/5/11 “坏人” [email protected]:

æˆ‘å’Œä½ ä¸€æ ·éƒ½æ˜¯ç”¨google翻译的。我不懂英文

I tried Google to translate this but I can’t understand it still…

English please? :slight_smile:

2009/5/11 “坏人” :
先把perl编译进nginx中。perl_modules是路径,perl_require是调用的文件
è¿™ä¸ªç¤ºä¾‹æ²¡ä»€ä¹ˆç”¨å•Šï¼Œä½ è¦å®žçŽ°ä»€ä¹ˆåŠŸèƒ½ï¼Ÿ
nginx里perl的用法和*nix下的没多大区别,稍作修改就可以用了

Posted at Nginx Forum: Re: Issues with Location: header in perl module

Posted at Nginx Forum: