title: Karate: Trying to get global headers working
body: <p>I'm trying to setup  a framework to run Graphql calls and create and E2E environment.</p>
  
  <p>I've got the following setup so far but i can't seem to get the headers part of it working.  i have managed to set the auth for each request and it all works but as it logs in for each request it doesn't really work as expected.</p>
  
  <p>I want do the following steps:</p>
  
  <ul>
  <li>run a login Test (different usernames valid/invalid)</li>
  <li>run a logout test (Ensure token is removed)</li>
  <li>Then login with correct user and extract the "set-cookie" header (to use globally for all future requests) </li>
  </ul>
  
  <p>I was trying to use the following:</p>
  
  <p>Karate-config.js</p>
  
  <pre><code>karate.callSingle('classpath:com/Auth/common-headers.feature', config);
  </code></pre>
  
  <p>headers.js</p>
  
  <pre><code>function fn() {
      var headers = {}
      headers["set-cookie"] = sessionAccessId
      karate.log('Cookie Value: ', headers)
  
      return headers
  }
  </code></pre>
  
  <p>common-headers.feature</p>
  
  <pre><code>Feature: Login to Application and extract header
  
  Background:
      * url serverAuthenticateUri
      * header Accept = 'application/json'
  
  Scenario: 'Login to the system given credentials'
  
  Given request { username: '#(username)', password: '#(password)'}
  When method post
  Then status 200
  And match $.success == '#(result)'
  And def myResult = response
  
  * def sessionAccessId = responseHeaders['set-cookie'][0]
  
  * configure headers = read('classpath:headers.js')
  * print 'headers:', karate.prevRequest.headers
  </code></pre>
  
  <p>feature-file.feature</p>
  
  <pre><code>Feature: sample test script
  
  Background:
    * url serverBaseUri
  
    * def caseResp = call read('classpath:com/E2E/POC/CommonFeatures/CreateCaseRequest.feature')
    * def caseReqId = caseResp.response.data.createCaseAndRequest.siblings[0].id
    * def caseId = caseResp.response.data.createCaseAndRequest.siblings[0].forensicCaseId
  
    * def graphQlCallsPath = 'classpath:com/E2E/POC/GraphQl/intForensic/'
    * def commmonFiles = 'classpath:E2E/CommonFiles/'
  
  
  Scenario: TC1a - Request Server Details from Config DB (1st Run):
            Should handle requesting Server Details Data from Config Database.
  
    * def queryFile = graphQlCallsPath + '20-TC1a_req_req_valid_id.graphql'
    * def responseFile = graphQlCallsPath + '20-TC1a_resp_req_valid_id.json'
  
    Given def query = read(queryFile)
    And replace query.reqId = caseReqId
    And request { query: '#(query)' }
    When method post
    Then status 200
    And json resp = read(responseFile)
    And replace resp.reqId = caseReqId
    And replace resp.caseID = caseId
    And match resp == $
  </code></pre>
  
  <p>I can log in correctly and i get the set-cookie token but this isn't being passed on the feature-file.feature and i get an error saying "not logged in" in the response. </p>
  
  <p>Any help appreciated! I might be looking at this totally wrong and i have tried to follow the shared-scope as much as i can but can't understand in.</p>