Nathan Thanks for your patience. Please find the answers below:
- Make sure that the backend API is returning the headers as multiple header values instead of comma separated values. If the backend itself returns as comma separated values (i.e. single header), it is not possible to loop through with the split.
- I used set-header policy (code snippet below) in the outbound section as described in the doc and able to validate that it indeed returned as multiple header values (yes, this only applies to standardized headers such as
Cookie
,Set-Cookie
) to the browser.
<outbound>
<set-header name="Set-Cookie" exists-action="override">
<value>Cookie1=Value1;Path=/;Expires=Wed, 21 Oct 2015 07:28:00 GMT;</value>
<value>Cookie2=Value3;Path=/;Expires=Wed, 21 Oct 2015 07:28:00 GMT;</value>
<value>Cookie3=Value3;Path=/;Expires=Wed, 21 Oct 2015 07:28:00 GMT;</value>
</set-header>
<base />
</outbound>
Output:
- You are right,
GetValueOrDefault
returns comma-separated response header values as described in the doc. Instead, you can follow the below code snippet to loop through the cookies to generate a string (comma separated values) and then assign it toSet-header
. You can even use split inside the for loop based on your scenario. Note:context.Response.Headers
returnsIReadOnlyDictionary
and hence you need to use Set-Header to override the values.
<set-header name="Set-Cookie" exists-action="override">
<value>@{
if (context.Response.Headers["Set-Cookie"] != null)
{
var outputCookies = new List<string>();
for (var i = 0; i < context.Response.Headers["Set-Cookie"].Count(); i++)
{
outputCookies.Add(context.Response.Headers["Set-Cookie"][i].Replace("Path=/;", "Path=/api;"));
}
return String.Join(",",outputCookies);
}
return "";
}</value>
</set-header>
Output:
Currently, it is not possible to set back the header ('Set-Cookie`) as multiple header values with the dynamic collection. If you are interested in this feature, please feel free to submit via https://aka.ms/apimwish and others with similar interests can upvote it too. This will help our product team prioritize the features.
I hope this helps with your questions and if I miss anything, please let me know.
If you found the answer to your question helpful, please take a moment to mark it as Yes
for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.