here's my code
What I don't undrstand is: my conditio is true, so the ADD cord is supposed to be SET. Unfortunately it doesn't work.
I set my variable: addingCors = true in a JS script before calling this Assign Message.
So is it possible to add conditions in a SET ?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="add-cors"> <DisplayName>Add CORS</DisplayName> <FaultRules/> <Properties/> <Set> <Step> <Headers> <Header name="Access-Control-Allow-Origin">{header-origin}</Header> <Header name="Access-Control-Allow-Headers">origin, x-requested-with, accept, content-type</Header> <Header name="Access-Control-Max-Age">3628800</Header> <Header name="Access-Control-Allow-Methods">GET, PUT, POST, DELETE</Header> </Headers> <Condition>(addingCors = true)</Condition> </Step> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="response"/> </AssignMessage>
Solved! Go to Solution.
You cannot add a Condition element under a Set element within AssignMessage.
Also, you have a stray <Step> element under Set. That shouldn't be there.
I think you want this:
<AssignMessage name="add-cors"> <Set> <Headers> <Header name="Access-Control-Allow-Origin">{header-origin}</Header> <Header name="Access-Control-Allow-Headers">origin, x-requested-with, accept, content-type</Header> <Header name="Access-Control-Max-Age">3628800</Header> <Header name="Access-Control-Allow-Methods">GET, PUT, POST, DELETE</Header> </Headers> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> </AssignMessage>
If you attach it in the Response flow, then you don't need AssignTo either.
The Step and Condition apply to flow configuration.
The AssignMessage is not a flow; it's a policy.
I would expect the proxy editor to flag your use of Step and Condition within AssignMessage as a violation of the schema. But I'm not sure that happens.