Azure 来自缓存的请求不使用CORS头

Azure 来自缓存的请求不使用CORS头,azure,cors,azure-api-management,Azure,Cors,Azure Api Management,使用缓存和CORS配置操作后,仅当响应来自缓存未命中时,命中端点才会返回所需的CORS头。 从缓存中获取响应时,标头将丢失 该操作的配置为: <policies> <inbound> <base /> <cache-lookup vary-by-developer="false" vary-by-developer-groups="false"> <vary-by-header&

使用缓存和CORS配置操作后,仅当响应来自缓存未命中时,命中端点才会返回所需的CORS头。 从缓存中获取响应时,标头将丢失

该操作的配置为:

<policies>
    <inbound>
        <base />
        <cache-lookup vary-by-developer="false" vary-by-developer-groups="false">
            <vary-by-header>Accept</vary-by-header>
            <vary-by-header>Accept-Charset</vary-by-header>
        </cache-lookup>
        <cors allow-credentials="true">
            <allowed-origins>
                <origin>http://example.com</origin>
            </allowed-origins>
            <allowed-methods>
                <!-- allow any -->
                <method>*</method>
            </allowed-methods>
            <allowed-headers>
                <!-- allow any -->
                <header>*</header>
            </allowed-headers>
        </cors>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <cache-store duration="300" />
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

接受
接受字符集
http://example.com
*
*

策略中节点的顺序很重要。在
cors
元素之前使用
cache lookup
元素会导致从缓存中获取响应,然后立即返回,而不会通过
cors
指令添加头。
解决方案是颠倒这两个元素的顺序,使
cors
出现在
缓存查找
之前,这意味着它总是被调用,并将相关的头添加到响应中,而不管它是否来自缓存。

非常感谢!这救了我一天!