Perl help

Hi guys,

I just need a quick hand with a rewrite rule im have issues with

i need to have a url like so
http://blah.com/text.php?bitstart=21000

i need to use the bitstart=21200
and using that to add the header
Content-Range: 21200
to a request before handing it of to a proxied site.

Of all things im having trouble getting bitstart=21200, in perl to use
it.

Kingsley F.
Technical Leader Content Services / Content Services Group

=============================================
Internode Systems Pty Ltd

PO Box 284, Rundle Mall 5000
Level 5 150 Grenfell Street, Adelaide 5000
Phone: +61 8 8228 2978
Fax: +61 8 8235 6978
Web: http://www.internode.on.net
http://games.on.net

On Thu, Feb 05, 2009 at 03:56:43PM +1030, Kingsley F. wrote:

to a request before handing it of to a proxied site.

Of all things im having trouble getting bitstart=21200, in perl to use it.

If you use 0.7.x:

    proxy_set_header  Content-Range  $arg_bitstart;

Other way is defining perl variable handler:

http {

perl_set  $content_range '
    sub {
        my $r = shift;
        my $a = $r->args;
        if ($a =~ /bitstart=(\d+)/) {
            return $1;
        }
        return "";
   }';

   ...

       proxy_set_header  Content-Range  $content_range;

Great that mostly helped however

                    if ($arg_bitstart && $arg_bitstart != 0){
                            proxy_set_header  Content-Range

bytes=$arg_bitstart-;
proxy_set_header Range
bytes=$arg_bitstart-;
}

I get this error

2009/02/06 11:12:38 [emerg] 31739#0: invalid condition “$arg_bitstart”
in
/etc/nginx/nginx.conf:111
2009/02/06 11:12:38 [emerg] 31739#0: the configuration file
/etc/nginx/nginx.conf test failed

Kingsley


From: “Igor S.” [email protected]
Sent: Thursday, February 05, 2009 5:50 PM
To: [email protected]
Subject: Re: perl help

On Fri, Feb 06, 2009 at 11:16:02AM +1030, [email protected]
wrote:

I get this error

2009/02/06 11:12:38 [emerg] 31739#0: invalid condition “$arg_bitstart” in
/etc/nginx/nginx.conf:111
2009/02/06 11:12:38 [emerg] 31739#0: the configuration file
/etc/nginx/nginx.conf test failed

nginx curerently does not support “&&”, etc inside “if”.

However, in this case

   if ($arg_bitstart) {

is enough as both “” and “0” are false.
The more stronger test is:

   if ($arg_bitstart ~ [1-9]\d+) {

On Fri, Feb 06, 2009 at 01:12:50PM +0300, Igor S. wrote:

                   }

However, in this case

   if ($arg_bitstart) {

is enough as both “” and “0” are false.
The more stronger test is:

   if ($arg_bitstart ~ [1-9]\d+) {
  •    if ($arg_bitstart ~ [1-9]\d+) {
    
  •    if ($arg_bitstart ~ ^[1-9]\d+$) {

getting there,

I have a new error now :slight_smile:

2009/02/06 21:35:23 [emerg] 10444#0: “proxy_set_header” directive is not
allowed here in /etc/nginx/nginx.conf:112
2009/02/06 21:35:23 [emerg] 10444#0: the configuration file
/etc/nginx/nginx.conf test failed

however it works if the if statement isn’t there.

Kingsley


From: “Igor S.” [email protected]
Sent: Friday, February 06, 2009 8:53 PM
To: [email protected]
Subject: Re: perl help

On Fri, Feb 06, 2009 at 09:36:41PM +1030, Kingsley F. wrote:

getting there,

I have a new error now :slight_smile:

2009/02/06 21:35:23 [emerg] 10444#0: “proxy_set_header” directive is not
allowed here in /etc/nginx/nginx.conf:112
2009/02/06 21:35:23 [emerg] 10444#0: the configuration file
/etc/nginx/nginx.conf test failed

however it works if the if statement isn’t there.

Something like this:

   set  $range  $http_range;

   if ($arg_bitstart ~ ^[1-9]\d+$) {
       set   $range  $arg_bitstart;
   }

   proxy_pass  ...;

   proxy_set_header  Content-Range  $range;
   proxy_set_header  Range          $range;