Azure API Management条件出站标头



我正在使用API Management来设置出站标头,到目前为止,使用此策略块使用单个域已经足够了

<outbound>
<base />
<set-header name="Access-Control-Allow-Origin" exists-action="override">
<value>https://example.com</value>
</set-header>
</outbound>

然而,我现在需要管理多个域Access-Control-Allow-Origin和基于域的批准列表。我已经尝试使用条件块,但这不起作用。

<outbound>
<base />
<choose>
<when condition="@(context.Request.OriginalUrl.Host ==  "example.com")">
<return-response>
<set-header name="Access-Control-Allow-Origin" exists-action="override">
<value>https://example.com</value>
</set-header>
</return-response>
</when>
<when condition="@(context.Request.OriginalUrl.Host ==  "example1.com")">
<return-response>
<set-header name="Access-Control-Allow-Origin" exists-action="override">
<value>https://example1.com</value>
</set-header>
</return-response>
</when>
<otherwise />
</choose>
</outbound>

我们有一个不断增加的域列表,需要处理以发送响应回客户端,如果请求的域与列表匹配。是否有更好的方法来处理这个问题,我该如何做?

CORS策略允许列出多个允许的源,并根据请求处理响应头。

最新更新