Ticket #6880: 6880_patch.diff

File 6880_patch.diff, 2.7 KB (added by Kellen, 16 years ago)

patch adding USE_X_FORWARDED_HOST setting in get_host, docs

  • django/http/__init__.py

     
    4545    def get_host(self):
    4646        """Returns the HTTP host using the environment or request headers."""
    4747        # We try three options, in order of decreasing preference.
    48         if 'HTTP_X_FORWARDED_HOST' in self.META:
     48        if settings.USE_X_FORWARDED_HOST and 'HTTP_X_FORWARDED_HOST' in self.META:
    4949            host = self.META['HTTP_X_FORWARDED_HOST']
    5050        elif 'HTTP_HOST' in self.META:
    5151            host = self.META['HTTP_HOST']
  • django/conf/global_settings.py

     
    2020# Whether to use the "Etag" header. This saves bandwidth but slows down performance.
    2121USE_ETAGS = False
    2222
     23# Whether to use the "HTTP_X_FORWARDED_HOST" header as the hostname. Useful for some
     24# virtual hosting situations.
     25USE_X_FORWARDED_HOST = False
     26
    2327# People who get code error notifications.
    2428# In the format (('Full Name', 'email@domain.com'), ('Full Name', 'anotheremail@domain.com'))
    2529ADMINS = ()
  • docs/ref/request-response.txt

     
    184184
    185185   .. versionadded:: 1.0
    186186
    187    Returns the originating host of the request using information from the
    188    ``HTTP_X_FORWARDED_HOST`` and ``HTTP_HOST`` headers (in that order). If
    189    they don't provide a value, the method uses a combination of
    190    ``SERVER_NAME`` and ``SERVER_PORT`` as detailed in `PEP 333`_.
     187   Returns the host of the request. If :setting:`USE_X_FORWARDED_HOST` is
     188   set to ``True``, the host provided in the ``HTTP_X_FORWARDED_HOST``
     189   header will be used, otherwise the host in the ``HTTP_HOST`` header is
     190   used. If neither header provides a value, the method uses a combination
     191   of ``SERVER_NAME`` and ``SERVER_PORT`` as detailed in `PEP 333`_.
    191192
    192193   .. _PEP 333: http://www.python.org/dev/peps/pep-0333/
    193194
  • docs/ref/settings.txt

     
    12031203
    12041204.. setting:: YEAR_MONTH_FORMAT
    12051205
     1206USE_X_FORWARDED_HOST
     1207--------------------
     1208
     1209Default: ``False``
     1210
     1211A boolean that specifies whether to use the ``HTTP_X_FORWARDED_HOST`` header as
     1212the hostname when generating absolute URLs from relative URLs. This can be
     1213useful for some virtual hosting configurations.
     1214
    12061215YEAR_MONTH_FORMAT
    12071216-----------------
    12081217
Back to Top