haproxy

Get all the details of a request in haproxy lua


Working with version 2.8

I'm trying to get some information from a request. This is just a test/local development phase. Trying to get URL, payload, params, headers etc. I see that haproxy has a fetches class and a txn http class which can get me some of the details I'm looking for. From what I can see in code used at different teams in my workplace, I can use the below functions to get different details of a request

headers : txn.http:req_get_headers()

payload : txn.sf:req_body()

Two questions

  1. How to get the params and url of a request?
  2. Is there some way to get all the attributes and functions of txn.sf, txn.http and txn.f class (like a python dir(classname) ) ? I tried printing it like below, no luck. I checked documentation too.
    for key, value in pairs(txn.f) do
        print("Keyf:", key)
        -- Check if it's a function and print its type
        if type(value) == "function" then
            print("  Type: Function")
        else
            print("  Type: Value")
            print("  Valuef:", value)
        end
    end

Solution

  • After a day of trial and error, apparently the answer can be derived from docs. config docs. Apparently when it says req.body, it means you can get the body from txn.sf:req_body() , for url txn.f:path(), for params txn.f:query(). The pattern seems to be to substitute dot in the config with an underscore (res.body , res_body())