Commit 7aec3486 authored by Adrian Holovaty's avatar Adrian Holovaty
Browse files

Fixed #2078 -- Improved HttpResponseRedirect and HttpResponsePermanentRedirect...

Fixed #2078 -- Improved HttpResponseRedirect and HttpResponsePermanentRedirect to percent-encode non-ASCII characters in the Location header. Thanks, Andrey

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3166 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 6b730e1e
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
from Cookie import SimpleCookie
from pprint import pformat
from urllib import urlencode
from urllib import urlencode, quote
from django.utils.datastructures import MultiValueDict

RESERVED_CHARS="!*'();:@&=+$,/?%#[]"

try:
    # The mod_python version is more efficient, so try importing it first.
    from mod_python.util import parse_qsl
@@ -242,13 +244,13 @@ class HttpResponse(object):
class HttpResponseRedirect(HttpResponse):
    def __init__(self, redirect_to):
        HttpResponse.__init__(self)
        self['Location'] = redirect_to
        self['Location'] = quote(redirect_to, safe=RESERVED_CHARS)
        self.status_code = 302

class HttpResponsePermanentRedirect(HttpResponse):
    def __init__(self, redirect_to):
        HttpResponse.__init__(self)
        self['Location'] = redirect_to
        self['Location'] = quote(redirect_to, safe=RESERVED_CHARS)
        self.status_code = 301

class HttpResponseNotModified(HttpResponse):