Search code examples
karate

append global header to every request


We have many karate tests and now we have a new requirement to send X-Host-Forwarder header with every request to server.

I added global request headers using

karate.configure('headers', { 'X-Host-Forwarder': 'account-hub' });

In each feature file we have feature based headers e.g.

configure headers = { Accept: #(mediaType), 'Content-Type': #(mediaType), 'Api-Key': #(apiKey) }

How can I append X-Host-Forwarder global header on every request along with headers specified in each feature file?


Solution

  • Note the quotes around X-Host-Forwarder. Your question is not clear at all, but I suspect that is the issue you faced.

    So it works, you can try this and see for yourself:

    * karate.configure('headers', { 'X-Host-Forwarder': 'account-hub' })
    * url 'https://httpbin.org/get'
    * method get
    

    To do this globally, do it in karate-config.js: https://github.com/karatelabs/karate#karate-configjs

    If the question is about appending, refer: https://stackoverflow.com/a/54303725/143475