openresty / lua-nginx-module

Embed the Power of Lua into NGINX HTTP servers
https://openresty.org/
11.33k stars 2.03k forks source link

[feature request] ngx.req.get_body_data() return first n bytes #2252

Closed Masterlvng closed 1 year ago

Masterlvng commented 1 year ago
ngx.req.get_body_data()

In some scenarios, we only want to read the first n bytes of the HTTP body. However, the ngx.req.get_body_data() always returns all the data. If the body size is large, the overhead of copying memory between the Lua VM and the Nginx worker will be even greater. So, can you add an optional "limit" parameter to this interface?

-- return first 1024
ngx.req.get_body_data(1024)
-- return all
ngx.req.get_body_data()

If you think this feature is valuable, I can submit a pull request.

thx