Multiple MAP implementation issue

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple MAP implementation issue

zakirenish
I have this map statements

=== This works well ======

map http_header1 var1 {
default "abc"
1a "def"
1b "ghi"

}

map http_header2 var2 {
default "123"
2a "445"
2b "678"
}

map http_header3 finalvar {
default "xxxx"
aaaa $var1
bbbb $var2
}

==========


Now I need to do regex on http_header3..

if I change the last map statement to..

map http_header3 finalvar {
default "xxxx"
~aaaa $var1
~bbbb $var2
}


This causes ERROR too much redirects.. so im confused...

Any input is appreciated.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,289153,289153#msg-289153

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Multiple MAP implementation issue

Maxim Dounin
Hello!

On Fri, Aug 21, 2020 at 11:46:44AM -0400, brutuz wrote:

> I have this map statements
>
> === This works well ======
>
> map http_header1 var1 {
> default "abc"
> 1a "def"
> 1b "ghi"
>
> }
>
> map http_header2 var2 {
> default "123"
> 2a "445"
> 2b "678"
> }
>
> map http_header3 finalvar {
> default "xxxx"
> aaaa $var1
> bbbb $var2
> }
>
> ==========

These statements are not going to work well, at least due to
multiple syntax errors (missing "$" characters, missing
semicolons).

> Now I need to do regex on http_header3..
>
> if I change the last map statement to..
>
> map http_header3 finalvar {
> default "xxxx"
> ~aaaa $var1
> ~bbbb $var2
> }

This is, again, is not going to pass even configuration syntax
check as it lacks required "$" characters before variable names
and semicolons.

> This causes ERROR too much redirects.. so im confused...

Too many redirects is likely a result in something else in your
configuration, since map statements does not cause it by itself.

An example of properly working configuration snippet, with syntax
errors fixed (and a "return 200..." block added to facilitate
testing):

    map $http_header1 $var1 {
        default "abc";
        1a "def";
        1b "ghi";
    }
   
    map $http_header2 $var2 {
        default "123";
        2a "445";
        2b "678";
    }
   
    map $http_header3 $finalvar {
        default "xxxx";
        ~aaaa $var1;
        ~bbbb $var2;
    }
   
    server {
        listen 8080;
        return 200 "finalvar: $finalvar\n";
    }

This can be easily tested with curl.  Simple tests follows:

$ curl -H 'Header3: ' http://127.0.0.1:8080/
finalvar: xxxx
$ curl -H 'Header3: aaaa' http://127.0.0.1:8080/
finalvar: abc
$ curl -H 'Header3: bbbb' http://127.0.0.1:8080/
finalvar: 123

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx