Multiple MAP implementation issue

Maxim Dounin mdounin at mdounin.ru
Fri Aug 21 21:45:28 UTC 2020


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/


More information about the nginx mailing list