1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

get headers working

This commit is contained in:
Kevin McCarthy
2012-05-30 22:03:04 -10:00
parent 38d71080ea
commit fcb36ba32a
2 changed files with 7 additions and 8 deletions

View File

@@ -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__':

View 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):