From 0bb8be0e5ba58dfff9648b4058acaa927837e605 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Mon, 7 Oct 2013 21:43:21 -0500 Subject: [PATCH 1/3] Parse cookies when users set custom Host header --- requests/cookies.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/requests/cookies.py b/requests/cookies.py index f3ac64f0..4d1708d4 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,14 @@ class MockRequest(object): return self.get_host() def get_full_url(self): - return self._r.url + if not self._r.headers.get('Host'): + return self._r.url + host = self._r.headers['Host'] + parsed = urlparse(self._r.url) + return urlunparse([ + parsed.scheme, host, parsed.path, parsed.params, parsed.query, + parsed.fragment + ]) def is_unverifiable(self): return True From df7aece2c8aef689a4b1f71126b93a5f09a3d168 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 10 Oct 2013 20:43:18 -0500 Subject: [PATCH 2/3] Comment our reasonsing for the special cases --- requests/cookies.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/requests/cookies.py b/requests/cookies.py index 4d1708d4..a53f2104 100644 --- a/requests/cookies.py +++ b/requests/cookies.py @@ -45,10 +45,14 @@ class MockRequest(object): return self.get_host() def get_full_url(self): + # 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 doain 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 From 6632fb87c0eceed91d48f2bf84144cd4d24f77b8 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Fri, 11 Oct 2013 20:42:52 -0500 Subject: [PATCH 3/3] Fix typo --- requests/cookies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requests/cookies.py b/requests/cookies.py index a53f2104..8b13d1f8 100644 --- a/requests/cookies.py +++ b/requests/cookies.py @@ -49,7 +49,7 @@ class MockRequest(object): # header if not self._r.headers.get('Host'): return self._r.url - # If they did set it, retrieve it and reconstruct the expected doain + # 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