#29427: RequestDataTooBig raised in request.py prevents Middleware from 
returning a
valid response
-------------------------------+------------------------------------
     Reporter:  S. Paquette    |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  HTTP handling  |                  Version:  1.11
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Accepted
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+------------------------------------

Comment (by S. Paquette):

 Replying to [comment:4 Josh Schneier]:
 > Is there any reason that this can't be handled using an exception
 handling middleware?
 >
 > {{{#!python
 > from django.http import JsonResponse
 > from django.core.exceptions import RequestDataTooBig
 >
 > class HandleDataTooBigMiddleware:
 >     def __init__(self, get_response):
 >         self.get_response = get_response
 >
 >     def __call__(self, request):
 >         return self.get_response(request)
 >
 >     def process_exception(self, request, exception):
 >         if isinstance(exception, RequestDataTooBig):
 >             return JsonResponse({'info': 'File too big'}, status=400)
 >         return None
 > }}}

 Per the author of #28106, this also doesn't work if the body isn't set; in
 fact that's how their Middleware is structured. (The one I pasted here is
 another option I tried when the exception handling Middleware wouldn't
 work.)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29427#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.158e470e59b2734fc8f698debaddd22b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to