From 94d1eabc798bf2e6f1d1771adc71571516289126 Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 13 Nov 2012 16:42:12 +0530 Subject: [PATCH] add cors to main dir, edit headers for cross origin --- chaloBEST/cors/__init__.py | 0 chaloBEST/cors/middleware.py | 15 +++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 chaloBEST/cors/__init__.py create mode 100644 chaloBEST/cors/middleware.py diff --git a/chaloBEST/cors/__init__.py b/chaloBEST/cors/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/chaloBEST/cors/middleware.py b/chaloBEST/cors/middleware.py new file mode 100644 index 0000000..2561d9b --- /dev/null +++ b/chaloBEST/cors/middleware.py @@ -0,0 +1,15 @@ +from django.http import HttpResponse + + +class AllowOriginMiddleware(object): + def process_request(self, request): + if request.method == 'OPTIONS': + return HttpResponse() + + def process_response(self, request, response): + origin = request.META.get('HTTP_ORIGIN') + if origin: + response['Access-Control-Allow-Origin'] = origin + response['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, DELETE, PUT' + response['Access-Control-Allow-Headers'] = 'Content-Type, Accept' + return response