1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 17:45:35 +00:00

improve mocked headers so urllib2 can handle redirects too

This commit is contained in:
Kevin McCarthy
2013-08-11 15:02:28 -10:00
parent 5eab2edd70
commit c7abde24b8

View File

@@ -17,9 +17,19 @@ class VCRHTTPResponse(object):
self.version = None
self._content = StringIO(self.recorded_response['body']['string'])
# We are skipping the header parsing (they have already been parsed
# at this point) and directly adding the headers to the header
# container, so just pass an empty StringIO.
self.msg = HTTPMessage(StringIO(''))
for key, val in self.recorded_response['headers'].iteritems():
self.msg.addheader(key, val)
# msg.addheaders adds the headers to msg.dict, but not to
# the msg.headers list representation of headers, so
# I have to add it to both.
self.msg.headers.append("{0}:{1}".format(key, val))
#self.msg.headers = ["{0}:{1}".format(k,v) for k, v in self.recorded_response['headers'].iteritems()]
self.length = self.msg.getheader('content-length') or None