I want to enable CORS in my Rackspace CluodFiles container, so after reading the docs, I see I have to set some container metadata (I'm using Python and 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)
And I get as output:
{'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'}
But the browser is not getting a Access-Control-Allow-Origin
in the OPTIONS
preflight request, so it cancels the AJAX call:
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
What's missing?
Thanks!
Rackspace has docs on how to enable CORS for a container here. Example 7.11 is a CORS Test Page that'll let you test your configuration outside of attempting file uploads.
Test CORS Page - accepts a token and a URL to an object or container and let's you try calling an HTTP method on it.
NOTE: I've removed the "DELETE" method as that can have undesired results (Such as deleting your container/object)
To set these values outside of pyrax or any other SDK, I've used the following code:
https://gist.github.com/chrisrasco/7455804
Remember to set your username, apikey, and path to your container in the appropriate places.