stewmoon,
I had a situation where I needed to change the header in every GET request (from inside a groovy script at RequestFilter.filterRequest) from json to application/x-www-form-urlencoded. I did not use the headers.clear() operation but had similar operations that the URLs above explain (message 4). I would guess when assigning headers to request.requestHeaders it is doing a replacement. Here is what I did
def headers = request.requestHeaders
log.info "\n\n\n\n"
log.info " This is the RequestFilter.filterRequest Groovy Script running now "
log.info "\n\n\n\n"
String theMethod = context.getProperty("httpMethod").toString()
String theGet = new String("GET")
if (theMethod.substring(0, 3) == theGet)
{
log.info ".....Found a GET!!!!!!!!!!!!!"
// In case of a GET request I did the following
log.info "headers (right before adding the urlencoded content type): " + headers log.info "headers size now: " + (request.requestHeaders.size())
headers.put( "Content-Type", "application/x-www-form-urlencoded") // Replace values with those you need
log.info "Added Content-Type: application/x-www-form-urlencoded"
request.requestHeaders = headers
log.info "headers size now: " + (request.requestHeaders.size())
// display the header
log.info "actual header is " + request.requestHeaders
}