Ticket #5157: apache_redirect.diff

File apache_redirect.diff, 2.1 KB (added by mgiger@…, 8 years ago)
  • http/__init__.py

     
    1616class Http404(Exception):
    1717    pass
    1818
     19class HttpInternalRedirect(Exception):
     20        "Redirect Apache to handle static file"
     21    def __init__(self, path):
     22        self.path = path
     23
    1924class HttpRequest(object):
    2025    "A basic HTTP request"
    2126
  • core/handlers/base.py

     
    105105            return http.HttpResponseForbidden('<h1>Permission denied</h1>')
    106106        except SystemExit:
    107107            pass # See http://code.djangoproject.com/ticket/1023
     108        except http.HttpInternalRedirect, e:
     109            raise e # re-raise exception to avoid default exception handler
    108110        except: # Handle everything else, including SuspiciousOperation, etc.
    109111            if settings.DEBUG:
    110112                from django.views import debug
  • core/handlers/modpython.py

     
     1from django.core.exceptions import *
    12from django.core.handlers.base import BaseHandler
    23from django.core import signals
    34from django.dispatch import dispatcher
     
    148149        dispatcher.send(signal=signals.request_started)
    149150        try:
    150151            request = ModPythonRequest(req)
    151             response = self.get_response(request)
    152152
     153            # check for a redirect to allow Apache to efficiently handle static files
     154            try:
     155                response = self.get_response(request)
     156            except http.HttpInternalRedirect, e:
     157                req.internal_redirect(e.path)
     158                return mod_python.apache.DECLINED
     159
    153160            # Apply response middleware
    154161            for middleware_method in self._response_middleware:
    155162                response = middleware_method(request, response)
Back to Top