Welcome! Log In Create A New Profile

Advanced

Re: Get $request_body before content handlers?

agentzh
July 09, 2012 12:52AM
Hello!

On Sun, Jul 8, 2012 at 2:38 PM, Mike Gagnon <mikegagnon@gmail.com> wrote:
>
> Thanks for the pointer! I just looked at the source for
> form-input-nginx-module.
>
> It gives me the impression that the function
> ngx_http_read_client_request_body() isn't guaranteed to read the complete
> request_body before it is time to find the value for a set_form_input
> variable. In other words. it seems possible that the directive
> "set_form_input $data" might not work if the request_body isn't fully read
> before ngx_http_set_form_input() is called.
>

No, you're wrong here. The request body is read in ngx_form_input's
own rewrite phase handler, which is always run before the standard
ngx_rewrite module's handler. The ngx_http_set_form_input() function
is run in the ngx_rewrite's handler, by injecting callbacks into
ngx_rewrite's location configuration by means the ngx_devel_kit's
set_var submodule. That's the magic going on here.

The 3rd-party module ngx_eval also relies on the relative running
order with the standard ngx_rewrite module on the same "rewrite"
phase.

> I gathered this impression because it looks like ctx->done is only set after
> request_body is fully read. However, the function ngx_http_set_form_input()
> only advances to the function ngx_http_form_input_arg() if ctx->done is set.
>

The running order is already guaranteed here so this is totally fine :)

> I would like to ensure that the request_body is fully read before my module
> attempts to read it during the rewrite phase.
>

This is surely guaranteed or things can break very easily in
production environments ;)

> Thanks for the Lua tips. Lua has a reputation for speed, but I am worried it
> won't be as performant as a well engineered C module. Normally, I wouldn't
> be concerned with minor speed improvements but I am specifically trying
> building my module to withstand CPU overload attacks. Within my context, it
> is critical that my module be able to classify incoming requests quickly.
>

Most of the heavy lifting is already done in pure C in ngx_lua. Lua is
just the glue so the performance is totally fine especially when
you're using LuaJIT 2.0 with ngx_lua.

> Do you think I am under-estimating Lua's performance capability?
>

You can try it out on your side ;)

Best regards,
-agentzh

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

Get $request_body before content handlers?

Mike Gagnon 1261 July 07, 2012 07:42PM

Re: Get $request_body before content handlers?

agentzh 507 July 07, 2012 11:20PM

Re: Get $request_body before content handlers?

Mike Gagnon 404 July 08, 2012 05:40PM

Re: Get $request_body before content handlers?

agentzh 453 July 09, 2012 12:52AM

Re: Get $request_body before content handlers?

Mike Gagnon 407 July 08, 2012 07:30PM

Re: Get $request_body before content handlers?

Mike Gagnon 500 July 08, 2012 08:20PM

Re: Get $request_body before content handlers?

agentzh 769 July 09, 2012 01:00AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

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