diff --git a/requests/cookies.py b/requests/cookies.py index ea56c065..12245fc5 100644 --- a/requests/cookies.py +++ b/requests/cookies.py @@ -8,7 +8,7 @@ requests.utils imports from here, so be careful with imports. import time import collections -from .compat import cookielib, urlparse, Morsel +from .compat import cookielib, urlparse, urlunparse, Morsel try: import threading @@ -45,7 +45,18 @@ class MockRequest(object): return self.get_host() def get_full_url(self): - return self._r.url + # Only return the response's URL if the user hadn't set the Host + # header + if not self._r.headers.get('Host'): + return self._r.url + # If they did set it, retrieve it and reconstruct the expected domain + host = self._r.headers['Host'] + parsed = urlparse(self._r.url) + # Reconstruct the URL as we expect it + return urlunparse([ + parsed.scheme, host, parsed.path, parsed.params, parsed.query, + parsed.fragment + ]) def is_unverifiable(self): return True