chaoslawful/lua-nginx-module — pull request #286 by aviramc (2013-10-02 15:16:01+00:00)
Title: New features for ngx_lua

I've added quite a few patches to ngx_lua, and recently I've merged it with the newest version.
Some of the changes relate to issues, and some to things that we've talked about.
Here's a summary of all the changes and the issues to which they relate:
- Sockets extensions:
- Added support for SSL sockets (includes the verification of the remote end's certificate). Related to issue #178
- Setting different timeouts for receive and send.
- Now read and write can be done from different Lua threads. Relates to issue #241.
- Added fake_close so that we won't be able to read again from the client socket after it is closed.
- receive API - added the option 'bsd_read', which enables to receive the maximum number of bytes given (like the BSD API, not LuaSocket API).
- Made the request socket (client socket) readable also when the request body was not read. This is useful when implementing protocol that require simultaenous reads and writes to and from the client. Relates to issue #242.
- Added functions for killing threads:
- ngx.thread.kill - kills a thread.
- ngx.thread.kill_sleeping - for a thread that has a loop with sleep - kills the thread if it's sleeping, otherwise waits for it to end.
- It seems that when a request is over, if there's a sleeping thread, it doesn't delete its timer. Added a fix for that. Related to issue #248.
- Added APIs to get and set the keepalive property of a request. This is useful for implementing protocols that use the raw request socket. The API is ngx.req.get_keepalive and ngx.req.set_keepalive.
- Added the directive lua_correct_location_header. When off, this causes Nginx not to correct relative 'Location' headers in responses. Default is on (the current beavior).
- Added the directive lua_enforce_content_type. When off, if no headers were set in the response, the 'Content-Type' header is not set. Default is on (the current beavior).
- Subrequest API - the method option can also now be a string. If the string is an unknown method, the subrequest's method field is set to NGX_HTTP_UNKNOWN, and the method_name field is set to the given method name. The previous numeric method still works.
- Streaming subrequest API - Added the ability to perform a 'streaming' subrequest, using ngx.location.capture_stream, meaning that the main request and the subrequest would run simultaneously. This is still preliminary, thus the feature is protected by a C macro. To enable it on compile time, the option '-DNGX_LUA_CAPTURE_DOWN_STREAMING' should be given to GCC.

I've tried to put each of the changes in a different branch in my fork of the repository, thus if you want to merge only specific features, you can merge a specific branch or cherry pick the relevant commits.

For more information about the streaming subrequest API, go to
https://groups.google.com/forum/?hl=en#!topic/openresty-en/2M6Z9BNtufQ