2012-11-13 11:12:12 +00:00
|
|
|
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'] = '*'
|
2012-11-13 11:12:12 +00:00
|
|
|
response['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, DELETE, PUT'
|
2012-11-13 11:15:54 +00:00
|
|
|
response['Access-Control-Allow-Headers'] = 'Content-Type, Accept, X-Requested-With'
|
2012-11-13 11:12:12 +00:00
|
|
|
return response
|