luakrakend

Kraken modify headers between backends


I have an endpoint with two backends. My goal is read response of first backend and put some headers to second (and all later) backend. I tried to use modifier/lua-backend.

My last attempt ended up with this (post step for the first endpoint)

local resp = response.load();
local respData = resp:data();
local x_user = respData:get('user_id');
local x_org = respData:get('org_id');
local req = request.load();
req:headers('x-user', x_user);
req:headers('x-org', x_org);

But second endpoint never got these headers. (I have added both x-user and x-org to input_headers list).

Am I missing something about scope of this operation? modifier/lua-proxy seem to work once before all backends (as pre) and once after all backends (as post).

How can I achieve this or is this even possible?


Solution

  • If you use lua-endpoint it works, atleast it worked for me. Something like this should work for you.

    "input_headers": [
        "Accept",
        "new"
    ],
    "extra_config": {
        "modifier/lua-endpoint": {
            "allow_open_libs": true,
            "pre": "local c = ctx.load(); c:headers('new',c:headers('original'));"
        }
    }
    

    Note: its written on the endpoint not the one which is proxying