Merge pull request #1660 from sigmavirus24/parse-cookies-when-users-set-host-header

Parse cookies when users set custom Host header
This commit is contained in:
2013-11-06 11:19:31 -08:00
+13 -2
View File
@@ -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