Comment (by bcail):
Would something like this work for the test case? Should I open a PR for
this?
{{{
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
index 402f282588..dc25d52ee2 100644
--- a/tests/test_client/tests.py
+++ b/tests/test_client/tests.py
@@ -26,7 +26,7 @@ from unittest import mock
from django.contrib.auth.models import User
from django.core import mail
-from django.http import HttpResponse, HttpResponseNotAllowed
+from django.http import HttpResponse, HttpResponseNotAllowed,
HttpResponseRedirect
from django.test import (
AsyncRequestFactory,
Client,
@@ -856,6 +856,36 @@ class ClientTest(TestCase):
response, "https://www.djangoproject.com/",
fetch_redirect_response=False
)
+ def test_external_redirect_http_host(self):
+ response_1 =
HttpResponseRedirect(redirect_to='https://www.djangoproject.com')
+ response_2 = HttpResponse()
+
+ with mock.patch('django.test.Client.request') as m:
+ m.side_effect = [response_1, response_2]
+ client = self.client_class()
+ response = client.get("/django_project_redirect/",
follow=True)
+
+ call_1_params = {
+ 'PATH_INFO': '/django_project_redirect/',
+ 'REQUEST_METHOD': 'GET',
+ 'SERVER_PORT': '80',
+ 'wsgi.url_scheme': 'http',
+ 'QUERY_STRING': ''
+ }
+ call_2_params = {
+ 'PATH_INFO': '/',
+ 'REQUEST_METHOD': 'GET',
+ 'SERVER_PORT': '80',
+ 'wsgi.url_scheme': 'https',
+ 'QUERY_STRING': '',
+ 'SERVER_NAME': 'www.djangoproject.com',
+ 'HTTP_HOST': 'www.djangoproject.com'
+ }
+ calls = m.mock_calls
+
+ self.assertEqual(calls[0], mock.call(**call_1_params))
+ self.assertEqual(calls[1], mock.call(**call_2_params))
+
def test_external_redirect_without_trailing_slash(self):
"""
Client._handle_redirects() with an empty path.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32106#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: bcail (added)
* has_patch: 0 => 1
Comment:
PR: https://github.com/django/django/pull/17414
--
Ticket URL: <https://code.djangoproject.com/ticket/32106#comment:3>
* owner: nobody => bcail
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32106#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32106#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"523fed1d2faafa6610f27dad9bbb7d7c4e122ea5" 523fed1]:
{{{
#!CommitTicketReference repository=""
revision="523fed1d2faafa6610f27dad9bbb7d7c4e122ea5"
Fixed #32106 -- Preserved HTTP_HOST in test Client when following
redirects.
Co-authored-by: David Sanders <shang.xia...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32106#comment:6>