Permalink
Browse files

Merge branch 'master' of github.com:revolunet/django-tasty-sample

  • Loading branch information...
2 parents 2908405 + c593e9c commit 43bf6f1ecd9777639eba155205a62611bbbef017 @revolunet committed Nov 1, 2011
Showing with 6 additions and 30 deletions.
  1. +5 −29 cors.py
  2. +1 −1 requirements.txt
View
34 cors.py
@@ -1,35 +1,11 @@
from django.conf import settings
-#: By default we'll set CORS Allow Origin * for all application/json responses
-DEFAULT_CORS_PATHS = (
- ('/', ('application/json', ),('*',), ),
-)
class CORSMiddleware(object):
- """
- From https://github.com/acdha/django-sugar/blob/master/sugar/middleware/cors.py
-
- Middleware that serves up representations with a CORS header to
- allow third parties to use your web api from JavaScript without
- requiring them to proxy it.
-
- See: http://www.w3.org/TR/cors/
-
- """
-
- def __init__(self):
- self.paths = getattr(settings, "CORS_PATHS", DEFAULT_CORS_PATHS)
def process_response(self, request, response):
- content_type = response.get('content-type', '').split(";")[0].lower()
-
- for path, types, allowed in self.paths:
- if request.path.startswith(path) and content_type in types:
-
- for domain in allowed:
- response['Access-Control-Allow-Origin'] = domain
- response['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT, DELETE'
- response['Access-Control-Max-Age'] = 1000
- response['Access-Control-Allow-Headers'] = '*'
- break
- return response
+ response['Access-Control-Allow-Origin'] = '*'
+ response['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT, DELETE'
+ response['Access-Control-Max-Age'] = 1000
+ response['Access-Control-Allow-Headers'] = request.META.get('HTTP_ACCESS_CONTROL_REQUEST_HEADERS', '*')
+ return response
View
2 requirements.txt
@@ -1,5 +1,5 @@
Django==1.3.1
-django-tastypie==0.9.9
+-e git+https://github.com/toastdriven/django-tastypie.git@e8af315211b07c8f48f32a063233cc3f76dd5bc2#egg=django_tastypie-dev
lxml==2.3.1
mimeparse==0.1.3
python-dateutil==1.5

0 comments on commit 43bf6f1

Please sign in to comment.