[ckan-changes] commit/ckan: 3 new changesets

Bitbucket commits-noreply at bitbucket.org
Fri Aug 19 11:22:11 UTC 2011


3 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/749cb3a087e3/
changeset:   749cb3a087e3
branch:      feature-1271-cors
user:        rgrp
date:        2011-08-19 13:03:13
summary:     [lib/base][s]: allow for CORS requests by setting relevant headers for all requests (fixes #1271).
affected #:  2 files (941 bytes)

--- a/ckan/lib/base.py	Mon Aug 15 18:06:04 2011 +0100
+++ b/ckan/lib/base.py	Fri Aug 19 12:03:13 2011 +0100
@@ -130,7 +130,12 @@
             model.Session.remove()
 
     def __after__(self, action, **params):
-        return
+        self._set_cors()
+
+    def _set_cors(self):
+        response.headers['Access-Control-Allow-Origin'] = "*"
+        response.headers['Access-Control-Allow-Methods'] = "POST, PUT, GET, OPTIONS"
+        response.headers['Access-Control-Allow-Headers'] = "X-CKAN-API-KEY, Content-Type"
 
     def _get_user(self, reference):
         return model.User.by_name(reference)


--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/tests/functional/test_cors.py	Fri Aug 19 12:03:13 2011 +0100
@@ -0,0 +1,19 @@
+import webtest
+from ckan.tests import TestController
+
+class TestCORS(TestController):
+
+    def test_options(self):
+        # need webtest as it has request method
+        self.ourapp = webtest.TestApp(self.wsgiapp)
+        out = self.ourapp.request('/', method='OPTIONS')
+        assert out.status_int == 200, out
+
+    def test_headers(self):
+        out = self.app.get('/')
+        headers = dict(out.headers)
+        print headers
+        assert headers['Access-Control-Allow-Origin'] == '*'
+        assert headers['Access-Control-Allow-Methods'] == "POST, PUT, GET, OPTIONS"
+        assert headers['Access-Control-Allow-Headers'] == "X-CKAN-API-KEY, Content-Type"
+


http://bitbucket.org/okfn/ckan/changeset/3e80ca4221a6/
changeset:   3e80ca4221a6
branch:      feature-1271-cors
user:        rgrp
date:        2011-08-19 13:17:31
summary:     [close-branch][xs]: closing this branch.
affected #:  0 files (0 bytes)

http://bitbucket.org/okfn/ckan/changeset/156e0a93776c/
changeset:   156e0a93776c
user:        rgrp
date:        2011-08-19 13:18:02
summary:     [merge,from-branch][s]: merge completed (minor) feature #1271 (CORS support).
affected #:  2 files (941 bytes)

--- a/ckan/lib/base.py	Mon Aug 15 18:06:04 2011 +0100
+++ b/ckan/lib/base.py	Fri Aug 19 12:18:02 2011 +0100
@@ -130,7 +130,12 @@
             model.Session.remove()
 
     def __after__(self, action, **params):
-        return
+        self._set_cors()
+
+    def _set_cors(self):
+        response.headers['Access-Control-Allow-Origin'] = "*"
+        response.headers['Access-Control-Allow-Methods'] = "POST, PUT, GET, OPTIONS"
+        response.headers['Access-Control-Allow-Headers'] = "X-CKAN-API-KEY, Content-Type"
 
     def _get_user(self, reference):
         return model.User.by_name(reference)


--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ckan/tests/functional/test_cors.py	Fri Aug 19 12:18:02 2011 +0100
@@ -0,0 +1,19 @@
+import webtest
+from ckan.tests import TestController
+
+class TestCORS(TestController):
+
+    def test_options(self):
+        # need webtest as it has request method
+        self.ourapp = webtest.TestApp(self.wsgiapp)
+        out = self.ourapp.request('/', method='OPTIONS')
+        assert out.status_int == 200, out
+
+    def test_headers(self):
+        out = self.app.get('/')
+        headers = dict(out.headers)
+        print headers
+        assert headers['Access-Control-Allow-Origin'] == '*'
+        assert headers['Access-Control-Allow-Methods'] == "POST, PUT, GET, OPTIONS"
+        assert headers['Access-Control-Allow-Headers'] == "X-CKAN-API-KEY, Content-Type"
+

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list