Forum: NGINX Issues with Location: header in perl module

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Michael S. (Guest)
on 2009-05-12 01:02
(Received via mailing list)
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
raptium (Guest)
on 2009-05-12 08:30
(Received via mailing list)
I think `header_out` should appear before `send_http_header`.
Igor S. (Guest)
on 2009-05-12 09:38
(Received via mailing list)
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;
"坏人" (Guest)
on 2009-05-13 00:54
(Received via mailing list)
先把perl编译进nginx中。perl_modules是路径,perl_require是调用的文件
这个示例没什么用啊,你要实现什么功能?
nginx里perl的用法和*nix下的没多大区别,稍作修改就可以用了

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1915,1922#msg-1922
Michael S. (Guest)
on 2009-05-13 01:07
(Received via mailing list)
I tried Google to translate this but I can't understand it still...

English please? :)

2009/5/11 "坏人" <removed_email_address@domain.invalid>:
"坏人" (Guest)
on 2009-05-13 05:11
(Received via mailing list)
我和你一样都是用google翻译的。我不懂英文
>I tried Google to translate this but I can't understand it still...

>English please? :)

>2009/5/11 "坏人" :
> 先把perl编译进nginx中。perl_modules是路径,perl_require是调用的文件
> 这个示例没什么用啊,你要实现什么功能?
> nginx里perl的用法和*nix下的没多大区别,稍作修改就可以用了
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,1915,1922#msg-1922
>
>
>

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,1915,1947#msg-1947
This topic is locked and can not be replied to.