In a raise-fault policy I am setting the following:
<Header name="Access-Control-Allow-Headers">{request.header.Access-Control-Request-Headers}</Header>
The “Access-Control-Request-Headers” has multiple values, such as “content-type, authorization”. To my surprise, “Access-Control-Allow-Headers” contains just the first part of the multiple values (“content-type” in the above example).
How can I assign a header in response to the exact same value as a header in request?
Solved! Go to Solution.
Hey Amar, you may want to consider -
You can refer to a variable named like this: request.header.HEADERNAME.values .
This holds all of the values of the header, in an array. Check the variables reference for more on that.
If you refer to that variable in a context in which a string is expected, then the value gets resolved as a comma-separated list, surrounded by square brackets, like this:
[ value1, value2 ]
Using the new static functions for message templates (overview here), you can use a substring to remove the brackets. This eliminates the need for the JS step.
This works for me
<AssignMessage name='AM-Response'> <Set> <Headers> <Header name='LoopbackHeader'>{substring(request.header.testheader.values,1,-1)}</Header> </Headers> <Payload contentType='application/json'>{ "status" : "ok" }</Payload> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew='false' transport='http' type='response'/> </AssignMessage>
Invoking that policy with a request message that includes 2 values for test-header, gives me the expected value in the response header.
The idea behind supporting static functions within message templates was to eliminate the need to call out to JavaScript for simple common operations, like substring.