There are several options:
1. try to read Content-Length header and (ngx.var.content_lenght / ngx.req.get_headers()["Content-Length"] / ngx.var.http_content_length) and assume that if it is zero or less, there is no body.
2. use ngx.req_get_body_data() and check if it is empty string (needs also ngx.req.read_body())
3. use ngx.req.socket() and check if it returns "no body" as error string.
So option 1 is obviously nice, but if there is no such header, we don't really know if there is body (or maybe used faked the header). Option 2 is better as we really do get the body and can check if it is empty, but if all we need to do is to check if there is a body, it feels a bit overkill to allocate strings and such. The option 3 feels like a trick. Relying on "no body" error code seems bit flaky. Also I'm not sure if there are any downsides of it (?).
I would prefer to have something like ngx.req.has_body() if it is possible, is it? What are your takes?
Regards
Aapo