Welcome! Log In Create A New Profile

Advanced

Re: Multiple MAP implementation issue

Maxim Dounin
August 21, 2020 05:46PM
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
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Multiple MAP implementation issue

brutuz August 21, 2020 11:46AM

Re: Multiple MAP implementation issue

Maxim Dounin August 21, 2020 05:46PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 309
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready