krakend / krakend-ce

KrakenD Community Edition: High-performance, stateless, declarative, API Gateway written in Go.
https://www.krakend.io
Apache License 2.0
1.86k stars 443 forks source link

adding multiple headers #869

Closed basaran closed 3 months ago

basaran commented 3 months ago

Environment info:

Version: 2.6.0 Linux 6.7.7-1-MANJARO x86_64

I understand we can add headers or modify existing ones by using header.Modifier. https://www.krakend.io/docs/backends/martian/#header-modifier

Is there a mechanism to add multiple headers using this interface, or do we need to use Lua or custom go plugins?

ridgarou commented 3 months ago

Hi, @basaran, to add multiple headers yo can use fifo.Group + header.Append

https://www.krakend.io/docs/backends/martian/#fifo-group https://www.krakend.io/docs/backends/martian/#append-a-header

like this:

   "backend": [
      {
        ....
        "extra_config": {
          "backend/http": { "return_error_code": true },
          "modifier/martian": {
            "fifo.Group": {
              "scope": [ "request" ],
              "aggregateErrors": true,
              "modifiers": [
                { "header.Append": { "scope": [ "request" ], "name": "X-NewHeader1", "value": "value1" } },
                { "header.Append": { "scope": [ "request" ], "name": "X-NewHeader2", "value": "value2" } }
              ]
            }
          }
        }
      }
   ]
basaran commented 3 months ago

Thank you very much for the snippet and the explanation. Much appreciated.