mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #25211 -- Added HttpRequest.get_port() and USE_X_FORWARDED_PORT setting.
This commit is contained in:
parent
f6259ce776
commit
4dcfbd7923
6 changed files with 67 additions and 1 deletions
|
@ -651,6 +651,38 @@ class HostValidationTests(SimpleTestCase):
|
|||
}
|
||||
request.get_host()
|
||||
|
||||
@override_settings(USE_X_FORWARDED_PORT=False)
|
||||
def test_get_port(self):
|
||||
request = HttpRequest()
|
||||
request.META = {
|
||||
'SERVER_PORT': '8080',
|
||||
'HTTP_X_FORWARDED_PORT': '80',
|
||||
}
|
||||
# Shouldn't use the X-Forwarded-Port header
|
||||
self.assertEqual(request.get_port(), '8080')
|
||||
|
||||
request = HttpRequest()
|
||||
request.META = {
|
||||
'SERVER_PORT': '8080',
|
||||
}
|
||||
self.assertEqual(request.get_port(), '8080')
|
||||
|
||||
@override_settings(USE_X_FORWARDED_PORT=True)
|
||||
def test_get_port_with_x_forwarded_port(self):
|
||||
request = HttpRequest()
|
||||
request.META = {
|
||||
'SERVER_PORT': '8080',
|
||||
'HTTP_X_FORWARDED_PORT': '80',
|
||||
}
|
||||
# Should use the X-Forwarded-Port header
|
||||
self.assertEqual(request.get_port(), '80')
|
||||
|
||||
request = HttpRequest()
|
||||
request.META = {
|
||||
'SERVER_PORT': '8080',
|
||||
}
|
||||
self.assertEqual(request.get_port(), '8080')
|
||||
|
||||
@override_settings(DEBUG=True, ALLOWED_HOSTS=[])
|
||||
def test_host_validation_disabled_in_debug_mode(self):
|
||||
"""If ALLOWED_HOSTS is empty and DEBUG is True, all hosts pass."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue