我想在我的 Rackspace CluodFiles 容器中启用 CORS,所以在阅读了文档之后,我看到我必须设置一些容器元数据(我正在使用 Python 和Pyrax):
from pyrax import cloudfiles
cloudfiles.set_container_metadata(container_name, {
'X-Container-Meta-Access-Control-Allow-Origin': 'localhost:8000',
'X-Container-Meta-Access-Control-Expose-Headers': 'Access-Control-Allow-Origin',
'X-Container-Meta-Access-Control-Max-Age': '10',
})
print cloudfiles.get_container_metadata(container_name)
我得到输出:
{'x-container-meta-access-control-allow-origin': 'localhost:8000',
'x-container-meta-access-control-expose-headers': 'Access-Control-Allow-Origin',
'x-container-meta-access-control-max-age': '10',
'x-container-meta-access-log-delivery': 'false'}
Access-Control-Allow-Origin
但是浏览器在预检请求中没有得到 a OPTIONS
,所以它取消了 AJAX 调用:
HTTP/1.1 401 Unauthorized
Content-Length: 131
Content-Type: text/html; charset=UTF-8
Allow: HEAD, GET, PUT, POST, COPY, OPTIONS, DELETE
X-Trans-Id: txXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Date: Wed, 13 Nov 2013 20:07:34 GMT
Connection: keep-alive
少了什么东西?
谢谢!