Welcome! Log In Create A New Profile

Advanced

Re: Best Practice Behaviour of Body Handler

agentzh
January 07, 2012 06:44AM
On Sat, Jan 7, 2012 at 12:10 AM, Alex Chamberlain
<alex@alexchamberlain.co.uk> 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:

<html>
<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>
</body>
</html>

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 https://github.com/alexchamberlain/ngx-mongodb. 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!
-agentzh

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

Best Practice Behaviour of Body Handler

Alex Chamberlain 1827 January 06, 2012 11:12AM

Re: Best Practice Behaviour of Body Handler

agentzh 510 January 07, 2012 06:44AM

Re: Best Practice Behaviour of Body Handler

Piotr Sikora 520 January 09, 2012 09:18AM

Re: Best Practice Behaviour of Body Handler

Alex Chamberlain 557 January 09, 2012 10:02AM

Re: Best Practice Behaviour of Body Handler

Piotr Sikora 550 January 09, 2012 10:10AM

Re: Best Practice Behaviour of Body Handler

Alex Chamberlain 485 January 09, 2012 03:10PM

Re: Best Practice Behaviour of Body Handler

Piotr Sikora 571 January 09, 2012 04:58PM



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

Online Users

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