krakend / krakend-lua

a lua interpreter for the KrakenD framework
Apache License 2.0
7 stars 14 forks source link

Modifying headers in first backend and pass modified header to the second #23

Closed smahdis closed 2 years ago

smahdis commented 3 years ago

I am using sequential in krakend.

I want to modify the header in first backend (for example add a new key/value to header) and then use this newly added header in the second backend.

Is that possible?

Currently I can modify the header in the first backed but the second backend doesn't see the affected header.

"backend": [
        {
          "host": [
            "http://ams_core:7086"
          ],
          "url_pattern": "/api/core/validation",
          "method": "GET",
          "extra_config": {
            "github.com/devopsfaith/krakend-lua/proxy/backend": {
              "post": "print('Lua proxy ....!');  local r = response.load(); local responseData = r:data() r:headers('Account_id', responseData:get('Account_id'));",
              "live": true,
              "skip_next": false
            }
          }
        },
        {
          "host": [
            "http://ams_core:7086"
          ],
          "url_pattern": "/api/core/menus",
          "method": "GET"
        }
      ],
kpacha commented 2 years ago

the subrequests created by the sequential proxy do not access or copy headers from responses.

if you need that behavior, you can make the first request from the lua script itself or create a plugin