chaloBEST/smsBEST/cors/middleware.py
2012-11-13 16:47:46 +05:30

16 lines
577 B
Python

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'] = '*'
response['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, DELETE, PUT'
response['Access-Control-Allow-Headers'] = 'Content-Type, Accept, X-Requested-With'
return response