Skip to content

Commit

Permalink
Merge pull request psf#1660 from sigmavirus24/parse-cookies-when-user…
Browse files Browse the repository at this point in the history
…s-set-host-header

Parse cookies when users set custom Host header
kennethreitz committed Nov 6, 2013
2 parents 7ccbcd2 + 6632fb8 commit a123f83
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions requests/cookies.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

import time
import collections
from .compat import cookielib, urlparse, Morsel
from .compat import cookielib, urlparse, urlunparse, Morsel

try:
import threading
@@ -45,7 +45,18 @@ def get_origin_req_host(self):
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

0 comments on commit a123f83

Please sign in to comment.