X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/f7ea1694cd74b49f8220e422291830a758521824..ac4596780e153ed1d9e46c98a2179eaeed7b034e:/contrib/penfield/middleware.py diff --git a/contrib/penfield/middleware.py b/contrib/penfield/middleware.py new file mode 100644 index 0000000..b25a28b --- /dev/null +++ b/contrib/penfield/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 HttpNotAcceptable errors and return an Http406 response. + 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