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.