Best Practice Behaviour of Body Handler

agentzh agentzh at
Sat Jan 7 11:41:56 UTC 2012

On Sat, Jan 7, 2012 at 12:10 AM, Alex Chamberlain
<alex at> wrote:
> Hi all,
> I've started to develop a RESTful interface onto MongoDB as an Nginx Module.

A mongodb driver for Nginx is certainly welcome! But will it block the
nginx worker processes on network I/O?

> I've started to work on PUT requests, and I'm just wondering about a couple
> of things with the body handler.
> My content handler registers the body handler
> using ngx_http_read_client_request_body.
> When this gets called, if everything goes correctly, I either want to send
> 204 No Content or 303 See Other. Therefore, no body. What should I be
> calling ngx_http_finalize_request with? I'm currently passing zero-length
> buffers, and I'm getting alerts, so it must be wrong...

Calling ngx_http_finalize_request(r, 303) should just work out of the
box with the default error page:

<head><title>303 See Other</title></head>
<body bgcolor="white">
<center><h1>303 See Other</h1></center>
<hr><center>nginx/1.0.10 (without pool)</center>

Calling ngx_http_finalize_request(r, 204) should do the work too.

You do not need to send response body data I think, unless you want to
output a custom error page (for the 303 case).

> On the other hand, if something goes wrong, I suspect I should still be
> calling ngx_http_finalize_request, right? If so, what should the arguements
> be then?

Just feed the HTTP status codes.

> Thanks for your help. My code can be found
> at I'd be very interested on
> any feedback, but please bear in mind I'm relatively inexperienced, so I
> expect to make mistakes and really won't mind any friendly advice.

I really hope that it is a nonblocking driver or it'll be almost
useless for production. Once we have a native mongodb driver for
Nginx, we can immediately reuse it as a client library in ngx_lua by
means of Nginx subrequests :D

Best wishes!

More information about the nginx-devel mailing list