From fcb36ba32a80b8d391a5bd755efa62ba976c3c31 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Wed, 30 May 2012 22:03:04 -1000 Subject: [PATCH] get headers working --- test.py | 5 ++--- vcr/stubs.py | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/test.py b/test.py index 76d8f0c..8e72e34 100644 --- 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__': diff --git a/vcr/stubs.py b/vcr/stubs.py index 69fe8e4..a631dde 100644 --- a/vcr/stubs.py +++ b/vcr/stubs.py @@ -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):