Ticket #13277: http-303-redirect-backward-compatible.diff

File http-303-redirect-backward-compatible.diff, 3.4 KB (added by Andreas Sommer <AndiDog@…>, 14 years ago)

Proposed patch

  • django/conf/global_settings.py

     
    395395DEFAULT_TABLESPACE = ''
    396396DEFAULT_INDEX_TABLESPACE = ''
    397397
     398# HTTP 303 ("see other") redirects were introduced in HTTP 1.1 and as such
     399# might not work correctly with very old browsers. Setting this to True
     400# lets HttpResponseSeeOtherRedirect objects return the status code 302
     401# instead of 303.
     402REDIRECT_303_BACKWARD_COMPATIBILITY = True
     403
    398404##############
    399405# MIDDLEWARE #
    400406##############
  • django/http/__init__.py

     
    607607        HttpResponse.__init__(self)
    608608        self['Location'] = iri_to_uri(redirect_to)
    609609
     610class HttpResponseSeeOtherRedirect(HttpResponse):
     611    def status_code(self):
     612        return settings.REDIRECT_303_BACKWARD_COMPATIBILITY and 302 or 303
     613    status_code = property(status_code)
     614
     615    def __init__(self, redirect_to):
     616        HttpResponse.__init__(self)
     617        self['Location'] = iri_to_uri(redirect_to)
     618
    610619class HttpResponseNotModified(HttpResponse):
    611620    status_code = 304
    612621
  • docs/ref/request-response.txt

     
    663663    Like :class:`HttpResponseRedirect`, but it returns a permanent redirect
    664664    (HTTP status code 301) instead of a "found" redirect (status code 302).
    665665
     666.. class:: HttpResponseSeeOtherRedirect
     667
     668    Like :class:`HttpResponseRedirect`, but it returns a "see other"
     669    (HTTP status code 303) instead of a "found" redirect (status code 302).
     670    This is the preferred redirect method in the `post-redirect-get pattern`_.
     671
    666672.. class:: HttpResponseNotModified
    667673
    668674    The constructor doesn't take any arguments. Use this to designate that a
     
    692698.. class:: HttpResponseServerError
    693699
    694700    Acts just like :class:`HttpResponse` but uses a 500 status code.
     701
     702.. _post-redirect-get pattern: http://en.wikipedia.org/wiki/Post/Redirect/Get
  • docs/ref/settings.txt

     
    13801380A tuple of profanities, as strings, that will trigger a validation error when
    13811381the ``hasNoProfanities`` validator is called.
    13821382
     1383.. setting:: REDIRECT_303_BACKWARD_COMPATIBILITY
     1384
     1385REDIRECT_303_BACKWARD_COMPATIBILITY
     1386-----------------------------------
     1387
     1388Default: ``True``
     1389
     1390Whether to replace ``HttpResponseSeeOtherRedirect`` (HTTP 303) redirects with
     1391the status code 302 ("found"). The status code 303 ("see other") was introduced
     1392in HTTP 1.1 and might not be understood by very old clients or clients that only
     1393understand HTTP 1.0.
     1394
     1395This setting does only apply to ``HttpResponseSeeOtherRedirect`` objects. It
     1396does not affect other (custom) response objects, for example responses with
     1397the attribute ``status_code = 303``.
     1398
     1399If targeted clients are expected to understand HTTP 1.1 and/or the status code
     1400303, this setting can be changed to ``False`` in order to leave the status code
     1401303 untouched.
     1402
    13831403.. setting:: RESTRUCTUREDTEXT_FILTER_SETTINGS
    13841404
    13851405RESTRUCTUREDTEXT_FILTER_SETTINGS
Back to Top