Fixed #25211 -- Added HttpRequest.get_port() and USE_X_FORWARDED_PORT setting.

This commit is contained in:
Matt Robenolt 2015-08-02 16:56:54 -07:00 committed by Tim Graham
parent f6259ce776
commit 4dcfbd7923
6 changed files with 67 additions and 1 deletions

View file

@ -254,6 +254,14 @@ Methods
:class:`~django.middleware.common.CommonMiddleware` or
:class:`~django.middleware.csrf.CsrfViewMiddleware`.
.. method:: HttpRequest.get_port()
.. versionadded:: 1.9
Returns the originating port of the request using information from the
``HTTP_X_FORWARDED_PORT`` (if :setting:`USE_X_FORWARDED_PORT` is enabled)
and ``SERVER_PORT`` ``META`` variables, in that order.
.. method:: HttpRequest.get_full_path()
Returns the ``path``, plus an appended query string, if applicable.

View file

@ -2621,6 +2621,19 @@ A boolean that specifies whether to use the X-Forwarded-Host header in
preference to the Host header. This should only be enabled if a proxy
which sets this header is in use.
.. setting:: USE_X_FORWARDED_PORT
USE_X_FORWARDED_PORT
--------------------
.. versionadded:: 1.9
Default: ``False``
A boolean that specifies whether to use the X-Forwarded-Port header in
preference to the ``SERVER_PORT`` ``META`` variable. This should only be
enabled if a proxy which sets this header is in use.
.. setting:: WSGI_APPLICATION
WSGI_APPLICATION
@ -3329,6 +3342,7 @@ HTTP
* :setting:`SIGNING_BACKEND`
* :setting:`USE_ETAGS`
* :setting:`USE_X_FORWARDED_HOST`
* :setting:`USE_X_FORWARDED_PORT`
* :setting:`WSGI_APPLICATION`
Logging

View file

@ -538,6 +538,9 @@ Requests and Responses
returning an :class:`~django.http.HttpResponseForbidden` so that
:data:`~django.conf.urls.handler403` is invoked.
* Added :meth:`HttpRequest.get_port() <django.http.HttpRequest.get_port>` to
fetch the originating port of the request.
Tests
^^^^^