From 2d11431e6372da75a993be9dc3c70b7aa6a04403 Mon Sep 17 00:00:00 2001 From: seba Date: Mon, 17 Oct 2011 19:39:54 +0200 Subject: [PATCH] Fixed pistons content-type issue. Pistons utils.Mimer.loader_for_type now get wrapped to remove everything behind a ; (including the ;). --- k4ever/api2/decorators.py | 11 +++++++++++ k4ever/api2/urls.py | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/k4ever/api2/decorators.py b/k4ever/api2/decorators.py index b729f20..a124f05 100644 --- a/k4ever/api2/decorators.py +++ b/k4ever/api2/decorators.py @@ -85,3 +85,14 @@ def requirePlugin(apiFunc): return ret return wrapper +def fix_mime(mime_func): + """ Fix mimetype by truncating everything behind a ';'. + + This is used to fix pistons ``piston.utils.Mimer.loader_for_type``.""" + @wraps(mime_func) + def wrapper(self, ctype): + if ctype and ctype.find(";") >= 0: + ctype = ctype.split(";")[0] + return mime_func(self, ctype) + return wrapper + diff --git a/k4ever/api2/urls.py b/k4ever/api2/urls.py index 600d69e..ae60471 100644 --- a/k4ever/api2/urls.py +++ b/k4ever/api2/urls.py @@ -3,6 +3,11 @@ from piston.resource import Resource from piston.authentication import HttpBasicAuthentication from api2.authentication import DjangoAuthentication, MultiAuthentication from api2.handlers import * +from api2.decorators import fix_mime +import piston.utils + +# piston does not understand mimetypes with charsets, HACK: fix loader_for_type +piston.utils.Mimer.loader_for_type = fix_mime(piston.utils.Mimer.loader_for_type) class CsrfExemptResource( Resource ): """ Except a :class:`Resource` from djangos CSRF-Framework.