]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
get headers working
authorKevin McCarthy <me@kevinmccarthy.org>
Thu, 31 May 2012 08:03:04 +0000 (22:03 -1000)
committerKevin McCarthy <me@kevinmccarthy.org>
Thu, 31 May 2012 08:03:04 +0000 (22:03 -1000)
test.py
vcr/stubs.py

diff --git a/test.py b/test.py
index 76d8f0cce73936474b7a7c59d73779494ff36971..8e72e3448aeb08d37a40e5b4ad80f6de896ec883 100644 (file)
--- a/test.py
+++ b/test.py
@@ -27,10 +27,9 @@ class TestHttpRequest(unittest.TestCase):
             self.assertEqual(body, urllib2.urlopen('http://www.iana.org/domains/example/').read())
 
     def test_response_headers(self):
-        headers = urllib2.urlopen('http://www.iana.org/domains/example/').info()
         with vcr.use_cassette('test/synopsis.yaml'):
-            self.assertEqual(headers, urllib2.urlopen('http://www.iana.org/domains/example/').info())
-            self.assertEqual(headers, urllib2.urlopen('http://www.iana.org/domains/example/').info())
+            headers = urllib2.urlopen('http://www.iana.org/domains/example/').info().items()
+            self.assertEqual(headers, urllib2.urlopen('http://www.iana.org/domains/example/').info().items())
 
 
 if __name__ == '__main__':
index 69fe8e4865d3e1e529b6f53f75c8d06141d3193f..a631dde2ce9a10a603b5c44b3b022d2a794ca94f 100644 (file)
@@ -1,4 +1,4 @@
-from httplib import HTTPConnection
+from httplib import HTTPConnection, HTTPMessage
 from cStringIO import StringIO
 from .files import save_cassette, load_cassette
 from .cassette import Cassette
@@ -7,17 +7,17 @@ from .cassette import Cassette
 class VCRHTTPResponse(object):
     def __init__(self, recorded_response):
         self.recorded_response = recorded_response
-        self.msg = recorded_response['status']['message']
         self.reason = recorded_response['status']['message']
         self.status = recorded_response['status']['code']
         self._content = StringIO(self.recorded_response['body']['string'])
 
+        self.msg = HTTPMessage(StringIO(''))
+        for k, v in self.recorded_response['headers'].iteritems():
+            self.msg.addheader(k, v)
+
     def read(self, chunked=False):
         return self._content.read()
 
-    def getheaders(self):
-        return self.recorded_response['headers']
-
 
 class VCRHTTPConnection(HTTPConnection):