来自缓存的请求没有 CORS headers
Requests from cache are served with no CORS headers
在使用缓存和 CORS 配置操作后,只有当响应来自缓存未命中时,才会到达端点 returns 所需的 CORS headers。
从缓存中获取响应时,缺少 headers。
操作的配置是:
<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>
策略中节点的顺序很重要。在 cors
元素之前使用 cache-lookup
元素会导致从缓存中获取响应,然后立即 return,而不会落入 cors
指令以添加 headers。
解决方案是颠倒这两个元素的顺序,使 cors
出现在 cache-lookup
之前,这意味着它总是被调用并将相关的 headers 添加到响应中,无论它是否出现是否来自缓存。
在使用缓存和 CORS 配置操作后,只有当响应来自缓存未命中时,才会到达端点 returns 所需的 CORS headers。 从缓存中获取响应时,缺少 headers。
操作的配置是:
<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>
策略中节点的顺序很重要。在 cors
元素之前使用 cache-lookup
元素会导致从缓存中获取响应,然后立即 return,而不会落入 cors
指令以添加 headers。
解决方案是颠倒这两个元素的顺序,使 cors
出现在 cache-lookup
之前,这意味着它总是被调用并将相关的 headers 添加到响应中,无论它是否出现是否来自缓存。