• General Discussion
  • ngx.req.get_body_data, ngx.req.get_body_file, ngx.var.request_body return nil

ngx.req.get_body_data, ngx.req.get_body_file, ngx.var.request_body return nil

server {
    listen       80;
    server_name  _;


    location / {
        # client_body_buffer_size     50M;
        # client_max_body_size        50M;
        proxy_request_buffering off;
        proxy_http_version 1.1;
        client_max_body_size 0;
        # lua_need_request_body on;
        proxy_pass   http://localhost:8000;

        access_by_lua_block {
            ngx.req.read_body()
            local body = ngx.req.get_body_data()
            --local body = ngx.req.get_body_file()
            --local body = ngx.var.request_body
            if body then
                ngx.log(ngx.STDERR, "THERE BODY")
                body = ngx.re.gsub(body, "string1", "string2")
                ngx.req.set_body_data(body)
            else
                ngx.log(ngx.STDERR, "NO BODY")
            end
        }

    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/local/openresty/nginx/html;
    }

}

I get "NO BODY" when I try to open a page on localhost. I tried local body = ngx.req.get_body_file() and local body = ngx.var.request_body and get the same issue.
what I do wrong or is it a bug?
nginx version: openresty/1.21.4.1

    I needed response, not request
    body_filter_by_lua_block {
    local body = ngx.arg[1]
    if body then
    body = ngx.re.gsub(body, "string1", "string2")
    ngx.arg[1] = body
    end
    }

      Write a Reply...