Welcome! Log In Create A New Profile

Advanced

Re: Reading request_body before passing to backend server

Maxim Dounin
May 13, 2013 03:10AM
Hello!

On Sat, May 11, 2013 at 09:53:47PM -0400, dktp1 wrote:

> I am trying to read if a specific value is set (passed) as a POST using
> request_body.
>
> What I am trying to do is:
>
> server {
> ..
> if ($request_body ~ "API-value-Iwanttocheck") {
> set $my_api "TRUE";
> }
>
> And later on pass to the backend server:
>
> location / {
> proxy_pass http://backend:80;
> }
>
>
> However, that never seems to match. I even enabled logging and modified my
> log_format to have:
>
> "
> "POSTREQUEST:$request_body"
> "
>
> And I can see in the log when I don't have the if statement. When I add the
> if statement, it doesn't show up in the logs any more.
>
> Anyone have any idea? Or a simple way to check if a value set via POST is
> actually there?

The $request_body variable isn't available in rewrites as request
body isn't yet read at this phase.

Request body can be read and examined using embedded perl module,
see here:

http://nginx.org/en/docs/http/ngx_http_perl_module.html

--
Maxim Dounin
http://nginx.org/en/donation.html

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

Reading request_body before passing to backend server

dktp1 May 11, 2013 09:53PM

Re: Reading request_body before passing to backend server

Maxim Dounin May 13, 2013 03:10AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 150
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready