From c7abde24b8c9b61c4875981cd618c1438f233d65 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 11 Aug 2013 15:02:28 -1000 Subject: [PATCH] improve mocked headers so urllib2 can handle redirects too --- vcr/stubs/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py index 18af6ba..6d40ea6 100644 --- a/vcr/stubs/__init__.py +++ b/vcr/stubs/__init__.py @@ -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 -- 2.43.0