Welcome! Log In Create A New Profile

Advanced

POST request body manipulation

Sandro Bordacchini
April 23, 2015 12:54PM
Hello everyone,

i have a problem in configuring Nginx.

I have a location that serves as a proxy for a well-specified url "/login".
This location can receive both GET and POST request.
GET request have no body and should be proxied to a default and
well-know host.
POST request contains the host to be proxied to in their body
(extractable by a regexp).

To avoid use of "if", i was using a map:

map $request_body $target_tenant_loginbody {
~*account=(.*)%40(?P<body_tenant>.*)&password.* $body_tenant;
default default.example.com;
}

location /login {
echo_read_request_body;

proxy_pass http://$target_tenant_loginbody:9000;

# Debug
proxy_set_header X-Debug-Routing-Value
$target_tenant_loginbody;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
}

This is not working (works with the GETs but not with the POSTs), seems
that the map returns always the default value even if the regexp works
(tested on regex101.com).
After a few tests, i understood that $request_body is empty or
non-initialized. I tried also with $echo_request_body, that seems
correctly initialized in location context but not in the map.

I read about a lot of issues and people having problem with empty
$request_body.

Maybe is there another approach you could direct me to?

Thanks in advance,
Sandro.


---
Questa e-mail รจ stata controllata per individuare virus con Avast antivirus.
http://www.avast.com

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

POST request body manipulation

Sandro Bordacchini April 23, 2015 12:54PM

Re: POST request body manipulation

pumbac December 17, 2015 12:44AM

Re: POST request body manipulation

Valentin V. Bartenev December 17, 2015 06:52AM

Re: POST request body manipulation

Valentin V. Bartenev December 17, 2015 06:58AM

Re: POST request body manipulation

pumbac December 17, 2015 06:36PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 109
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