Forum Discussion

Bipedal029's avatar
Bipedal029
Occasional Contributor
6 years ago
Solved

How to add custom headers at parent level

Hello,   I am trying to add custom headers at the parent level so that every request does not have to be individually tailored.  I see there may be some scripting options or property expansions but...
  • Bill_In_Irvine's avatar
    Bill_In_Irvine
    6 years ago

    You can do this at the parent level (by that I am guessing so that all requests use the same headers is what you want) - by doing so in an event handler. 

     

    So that in the RequestFilter.filterRequest event handler if you want to add "Content-Type: application/x-www-form-urlencoded" as a header you can do it the following way:

     

    def headers = request.requestHeaders
    
    // I clear out all request content, but you might not want to do this:
    context.setProperty("requestContent", '')
    request.requestContent = ''
    
    // add the header
    headers.put( "Content-Type", "application/x-www-form-urlencoded") 
    
    request.requestHeaders = headers
    
    
    

    Now every request will have the "application/x-www-form-urlencoded" Content-Type.

     

    Bill