Sunday, February 13, 2011

Day 19 - Echo module and where nginx stops with posts (or not)

I keep seeing the echo module mentioned here and there. Plus, it's written by agentzh who is definitely oen of the most active guys on the mailing list. With Maxim Dounim and Igor Himself. These three seem to be the top guns of nginx. When they say something on the mailing list and you think they are wrong you'd better reconsider: they are right and you are wrong...

So, I went ahed and read the documentation of the HttpEchoModule. It's the first one I read from head to toe. And it is very instructive: the directives are very simple, they are well documented and the examples usually point things that are definitely worth understanding. As a side note to this reading, I was wrong on day 15 - no loops in nginx: nginx can loop. Or at least the echo module can. It is not one of the official modules so I guess it does not count and I was right... :D But, the fact and the matter is that you can loop through something like query arguments by using echo_foreach_split/echo_end. But I guess this works only for directives of the echo module. If anybody cares to test it and let me know. If it works for other stuff, I'll take a look at the code because I have no idea how this is possible.

Speaking of arguments and retrieving them. This comes for "free" in nginx for the arguments in the URI as the URI is fully parsed and the corresponding fields in the ngx_http_request_t structure. But (yes, there is a but) it's much more complicated if you want to retrieve what is in the body of your request (like parameters from a POST form). This has to do with the body being potentially a big chunk of data (I heard people upload videos on crappy sites like youtube.com... ;)) and nginx handling this as efficiently as possible. For some insight on how this could/should be done when developing your module, have a look at the forum thread Trouble getting the request body of a HTTP POST.

Ah, and one more thing: I don't know why but this blog made it to the home page of Pingy. I didn't even know about this site 2 hours ago... Another web mystery, I guess.

No comments:

Post a Comment