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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user