Project

General

Profile

[Solved] How to receive the POST content with lua

Added by alfredng almost 5 years ago

Here is my lighttpd.conf.
$HTTP["url"] =~ "^/api" {
magnet.attract-physical-path-to = ( "/home/lighttpd-1.4.53/x64/www/demo.lua" )
}
I can receive all variables just like lighty.request", "lighty.env", "lighty.req_env" but can not receive the POST content with lua.How can I receive the POST content with lua?
lighttpd version 1.4.53 OS ubuntu18.04


Replies (4)

RE: How to receive the POST content with lua - Added by gstrauss almost 5 years ago

Sorry, mod_magnet does not support that.

When mod_magnet runs lua code on the request headers, the request body may not have been received yet.

Dynamic backends (CGI, FastCGI, SCGI, proxy, wstunnel) are able to handle request bodies, and the request body is sent asynchronously to a backend while lighttpd continues to handle other requests. On the other hand, mod_magnet runs lua synchronously inside lighttpd, so mod_magnet is not intended for large amounts of lua code or lua code which makes blocking calls.

May I ask what you are trying to achieve with lua and if you think it must be run inside lighttpd?

Creating a new module, say "mod_lua" which operates as a backend handler (and is called only once the request body is fully buffered by lighttpd, perhaps on disk) is possible, but has not been done. Questions would need to be answered for how the request body would be provided to lua, and what do to with the request body if it were very large. (Keeping the request body entirely in memory is avoided in lighttpd since the request body can be quite large.)

RE: How to receive the POST content with lua - Added by alfredng almost 5 years ago

Thanks for your answers.
I use lighttpd in ARM.
I am green,so modify a new module is difficult to me.
I see that, lighttpd2 has lua API:

https://doc.lighttpd.net/lighttpd2/core_lua.html

Virtual Request
Fields:

con(ro): Connection
in(ro): Chunk Queue, read request post content
out(ro): Chunk Queue, write response content
env(ro): Environment, (fast)cgi environment
req(ro): Request, data from request header
resp(ro): Response, response header data
phys(ro): Physical, paths and filenames
is_handled(ro): whether vrequest is already handled
has_response(ro): whether the response headers (and status) is available

Will it be supported in lighttpd2?
I mean I can get the request body with lua in lighttpd2?

RE: How to receive the POST content with lua - Added by gstrauss almost 5 years ago

May I ask what you are trying to achieve with lua and if you think it must be run inside lighttpd?

You did not answer the question.

lighttpd2 is an experimental branch that others have worked on, but currently have no plans of releasing or supporting. caveat emptor.

RE: How to receive the POST content with lua - Added by alfredng almost 5 years ago

May I ask what you are trying to achieve with lua and if you think it must be run inside lighttpd?

I just study lighttpd.

Thanks!

    (1-4/4)