Slightly changed the way we handle non-UTF-8 encoded URIs (see [6475]). Made it

easier to subclass the current behaviour, if needed. Fixed #5738.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6550 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-10-20 07:42:34 +00:00
parent e60c26d5bb
commit f34935c37f
2 changed files with 23 additions and 14 deletions

View File

@ -14,7 +14,7 @@ import os
class ModPythonRequest(http.HttpRequest):
def __init__(self, req):
self._req = req
self.path = force_unicode(req.uri, errors='ignore')
self.path = force_unicode(req.uri)
def __repr__(self):
# Since this is called as part of error handling, we need to be very
@ -136,6 +136,8 @@ class ModPythonRequest(http.HttpRequest):
method = property(_get_method)
class ModPythonHandler(BaseHandler):
request_class = ModPythonRequest
def __call__(self, req):
# mod_python fakes the environ, and thus doesn't process SetEnv. This fixes that
os.environ.update(req.subprocess_env)
@ -150,13 +152,16 @@ class ModPythonHandler(BaseHandler):
dispatcher.send(signal=signals.request_started)
try:
request = ModPythonRequest(req)
response = self.get_response(request)
# Apply response middleware
for middleware_method in self._response_middleware:
response = middleware_method(request, response)
try:
request = self.request_class(req)
except UnicodeDecodeError:
response = http.HttpResponseBadRequest()
else:
response = self.get_response(request)
# Apply response middleware
for middleware_method in self._response_middleware:
response = middleware_method(request, response)
finally:
dispatcher.send(signal=signals.request_finished)

View File

@ -75,7 +75,7 @@ def safe_copyfileobj(fsrc, fdst, length=16*1024, size=0):
class WSGIRequest(http.HttpRequest):
def __init__(self, environ):
self.environ = environ
self.path = force_unicode(environ['PATH_INFO'], errors='ignore')
self.path = force_unicode(environ['PATH_INFO'])
self.META = environ
self.method = environ['REQUEST_METHOD'].upper()
@ -179,6 +179,7 @@ class WSGIRequest(http.HttpRequest):
class WSGIHandler(BaseHandler):
initLock = Lock()
request_class = WSGIRequest
def __call__(self, environ, start_response):
from django.conf import settings
@ -194,13 +195,16 @@ class WSGIHandler(BaseHandler):
dispatcher.send(signal=signals.request_started)
try:
request = WSGIRequest(environ)
response = self.get_response(request)
# Apply response middleware
for middleware_method in self._response_middleware:
response = middleware_method(request, response)
try:
request = self.request_class(environ)
except UnicodeDecodeError:
response = http.HttpResponseBadRequest()
else:
response = self.get_response(request)
# Apply response middleware
for middleware_method in self._response_middleware:
response = middleware_method(request, response)
finally:
dispatcher.send(signal=signals.request_finished)