From 1c871f4d3199a94dcdbe53c9f28f90791a69701e Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 5 Feb 2014 06:37:37 +0000 Subject: [PATCH] add method to add Access-Control-Allow-Origin to HttpFileResponses --- ox/django/http.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ox/django/http.py b/ox/django/http.py index df73ce8..a3f773c 100644 --- a/ox/django/http.py +++ b/ox/django/http.py @@ -47,5 +47,12 @@ def HttpFileResponse(path, content_type=None, filename=None): response['Content-Disposition'] = 'attachment; filename*=UTF=8''%s' % quote(filename) response['Expires'] = datetime.strftime(datetime.utcnow() + timedelta(days=1), "%a, %d-%b-%Y %H:%M:%S GMT") + + def allow_access(): + for key in ('X-Accel-Redirect', 'X-Sendfile'): + if key in response: + del response[key] + response['Access-Control-Allow-Origin'] = '*' + response.allow_access = allow_access return response