[Django] #25211: Add USE_X_FORWARDED_PORT setting and HttpRequest.get_port()

6 views
Skip to first unread message

Django

unread,
Aug 3, 2015, 12:53:18 PM8/3/15
to django-...@googlegroups.com
#25211: Add USE_X_FORWARDED_PORT setting and HttpRequest.get_port()
-------------------------------+--------------------------------------
Reporter: mattrobenolt | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Keywords: port, server_port, proxy
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
It's be nice to internally have a way to reference the "real" port number
when behind a proxy.

Today, as an example:

If you were running a load balancer on port 80, which proxied back to an
nginx which was running on 8080, it's possible that `get_host()` would
resolve your request back to `example.com:8080` instead of the proper
`example.com` since `SERVER_PORT` is coming from what nginx was listening
on.

This just adds a proper method to `get_port()` and respect an optional `X
-Forwarded-Port` header.

The benefits of this being internal to Django, is because anywhere that
Django tries to resolve the port internally, we should be utilizing this
method. This issue is easy to correct in user-land, but a bit harder when
an internal Django method utilizes `SERVER_PORT` directly. The only option
is to have a middleware which sets `request.META['SERVER_PORT'] =
request.META['HTTP_X_FORWARDED_PORT']` which is less than ideal IMO since
it's overloading the meaning of the variable.

This is also relevant for https://github.com/django/django/pull/4337 since
in the wild, we hit an issue with `SERVER_PORT` not reflecting what the
upstream actually was, which caused issues. So this would unify and make
https://github.com/django/django/pull/4337 leverage the new `get_port()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/25211>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 3, 2015, 12:54:43 PM8/3/15
to django-...@googlegroups.com
#25211: Add USE_X_FORWARDED_PORT setting and HttpRequest.get_port()
-------------------------------------+-------------------------------------

Reporter: mattrobenolt | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: port, server_port, | Triage Stage: Accepted
proxy |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by mattrobenolt):

* needs_docs: => 0
* needs_better_patch: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25211#comment:1>

Django

unread,
Aug 3, 2015, 12:56:18 PM8/3/15
to django-...@googlegroups.com
#25211: Add USE_X_FORWARDED_PORT setting and HttpRequest.get_port()
-------------------------------------+-------------------------------------

Reporter: mattrobenolt | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: port, server_port, | Triage Stage: Ready for
proxy | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/25211#comment:2>

Django

unread,
Aug 4, 2015, 9:59:52 AM8/4/15
to django-...@googlegroups.com
#25211: Add USE_X_FORWARDED_PORT setting and HttpRequest.get_port()
-------------------------------------+-------------------------------------
Reporter: mattrobenolt | Owner: nobody
Type: New feature | Status: closed

Component: HTTP handling | Version: master
Severity: Normal | Resolution: fixed

Keywords: port, server_port, | Triage Stage: Ready for
proxy | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"4dcfbd792342667174834c40e792f1b8ac2f0609" 4dcfbd79]:
{{{
#!CommitTicketReference repository=""
revision="4dcfbd792342667174834c40e792f1b8ac2f0609"
Fixed #25211 -- Added HttpRequest.get_port() and USE_X_FORWARDED_PORT
setting.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25211#comment:3>

Reply all
Reply to author
Forward
0 new messages