chaloBEST/smsBEST/cors/middleware.py

16 lines
577 B
Python
Raw Permalink Normal View History

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:
2012-11-13 11:14:25 +00:00
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