﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28337	fetch_redirect_response from assertRedirects doesn't honor HTTP_HOST setting in self.client.get	Roland van Laar	Hasan Ramezani	"I would like to see `assertRedirects` honor the `HTTP_HOST` settings in self.client.get.

I'm writing middleware that checks if `request.get_host()` is coupled to a site, else we do a redirect to an external domain.
{{{
def test_redirect(self):
    response = self.client.get(""/"", follow=False, HTTP_HOST=self.site1.domain)
    self.assertRedirects(response, '/accounts/login/?next=', fetch_redirect_response=True)
}}}
The `assertRedirect` does an extra request to follow the redirect. What goes wrong is that the HTTP_HOST with the request is not set to
'{{ self.site1.domain }}'  but to `testserver`. This results in a redirect to our external domain. 

Middleware code:
{{{
class SiteMiddleware(object):
    def __init__(self, get_response):
        self.get_response = get_response
    def __call__(self, request):
        host = self.request.get_host()
        try:
            request.site = Site.objects.get(domain=host)
        except ObjectDoesNotExist:
            return HttpResponseRedirect(""http://example.com"")
        return self.get_response(request)
}}}"	Cleanup/optimization	closed	Testing framework	1.11	Normal	fixed			Accepted	1	0	0	0	0	0
