in cassette/cassette_library.py [0:0]
def from_httplib_connection(cls, host, port, method, url, body,
headers, will_hash_body=False):
"""Create an object from an httplib request."""
if headers:
if 'Host' in headers:
# 'Host' is already covered explicitly below, remove from the
# hash so hostname/post are easy to change and sed the file
del headers['Host']
headers = hashlib.md5(repr(sorted(headers.items()))).hexdigest()
if will_hash_body:
if body:
body = hashlib.md5(body).hexdigest()
else:
body = ''
if url:
# instantiated to 0.0.0.0 so we can parse
parsed_url = urlparse('http://0.0.0.0' + url)
url = parsed_url.path
query = hashlib.md5(parsed_url.query + '#' +
parsed_url.fragment).hexdigest()
else:
# requests/urllib3 defaults to '/' while urllib2 is ''. So this
# value should be '/' to ensure compatability.
url = '/'
query = ''
name = ("httplib:{method} {host}:{port}{url} {query} "
"{headers} {body}").format(**locals())
else:
# note that old yaml files will not contain the correct matching
# query and body
name = ("httplib:{method} {host}:{port}{url} "
"{headers} {body}").format(**locals())
name = name.strip()
return name