Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inspect POST body in nginx (HttpLuaModule)

Tags:

post

nginx

lua

My goal is to inspect a body of the POST request and compare it to some list of key-value pairs on nginx. In my situation POST requests will always be in JSON format. Each request will contain a key:value pair like this: "transaction":"12345" or "transaction":"098765". Mean the key "transaction" will always be there and value will change some time. I was thinking to use lua-nginx-module to inspect a post body and than compare it with key-value from let's say memcached. I don't have any code to show yet, but I will try to update a question, some time soon. I was wondering if someone could help me get started, with this or show how it can be done.

like image 390
Vor Avatar asked Dec 07 '22 05:12

Vor


1 Answers

This is what I did:

server {
        listen 80;
        location /api/setdata {           
            lua_need_request_body on;
            content_by_lua_file template/content.lua;
        }       
    }

template/content.lua:

function processRequest()
    ngx.req.read_body()
    local request_body = ngx.req.get_body_data()  
    ngx.say(request_body)
end
like image 56
Teoman shipahi Avatar answered Jan 01 '23 14:01

Teoman shipahi