X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/45be080dd7108e1d2effe22eedb5106501cd6408..819fc766fd18514fdd45cf514efdd91739210e62:/philo/contrib/winer/middleware.py?ds=sidebyside diff --git a/philo/contrib/winer/middleware.py b/philo/contrib/winer/middleware.py new file mode 100644 index 0000000..a0cd649 --- /dev/null +++ b/philo/contrib/winer/middleware.py @@ -0,0 +1,14 @@ +from django.http import HttpResponse +from django.utils.decorators import decorator_from_middleware + +from philo.contrib.penfield.exceptions import HttpNotAcceptable + + +class HttpNotAcceptableMiddleware(object): + """Middleware to catch :exc:`~philo.contrib.penfield.exceptions.HttpNotAcceptable` and return an :class:`HttpResponse` with a 406 response code. See :rfc:`2616`.""" + def process_exception(self, request, exception): + if isinstance(exception, HttpNotAcceptable): + return HttpResponse(status=406) + + +http_not_acceptable = decorator_from_middleware(HttpNotAcceptableMiddleware) \ No newline at end of file