Hello,
I need to assign a header name and value from variables. While the second is possible with variable interpolation, I couldn't find a way to do the same the header name. If Assign Message policy isn't compatible with such use case, I can use whatever other policy or script.
Please help!
Solved! Go to Solution.
Within AssignMessage, The Header VALUE can be set via a variable. The Header NAME cannot.
<AssignMessage name='AM-Set-Header'>
<Set>
<Headers>
<!--
using this syntax, the value in the variable named 'variable1'
will be set into the header 'Fixed-Name'
-->
<Header name='Fixed-Name'>{variable1}</Header>
</Headers>
</Set>
</AssignMessage>
But you can use JavaScript to set values into headers that have dynamically-determined names.
<JavaScript name='JS-Set-Dynamic-Header'>
<Source>
var n = context.getVariable('name-of-header-to-set');
var v = context.getVariable('variable-containing-value');
context.setVariable('request.header.' + n, v);
</Source>
</JavaScript>
Within AssignMessage, The Header VALUE can be set via a variable. The Header NAME cannot.
<AssignMessage name='AM-Set-Header'>
<Set>
<Headers>
<!--
using this syntax, the value in the variable named 'variable1'
will be set into the header 'Fixed-Name'
-->
<Header name='Fixed-Name'>{variable1}</Header>
</Headers>
</Set>
</AssignMessage>
But you can use JavaScript to set values into headers that have dynamically-determined names.
<JavaScript name='JS-Set-Dynamic-Header'>
<Source>
var n = context.getVariable('name-of-header-to-set');
var v = context.getVariable('variable-containing-value');
context.setVariable('request.header.' + n, v);
</Source>
</JavaScript>
works great!