1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 17:45:35 +00:00

change response format

This commit is contained in:
Kevin McCarthy
2014-05-03 19:54:00 -10:00
parent 1f99ede46f
commit a65da12aeb
2 changed files with 8 additions and 7 deletions

View File

@@ -2,13 +2,13 @@ import six
def convert_to_bytes(resp): def convert_to_bytes(resp):
resp = convert_headers_to_bytes(resp) #resp = convert_headers_to_bytes(resp)
resp = convert_body_to_bytes(resp) resp = convert_body_to_bytes(resp)
return resp return resp
def convert_to_unicode(resp): def convert_to_unicode(resp):
resp = convert_headers_to_unicode(resp) #resp = convert_headers_to_unicode(resp)
resp = convert_body_to_unicode(resp) resp = convert_body_to_unicode(resp)
return resp return resp

View File

@@ -48,15 +48,16 @@ def parse_headers(header_list):
HTTPMessage HTTPMessage
""" """
header_string = b"" header_string = b""
for k, v in header_list.items(): for key, values in header_list.items():
for v in v: for v in values:
header_string += k.encode('utf-8') + b":" + v.encode('utf-8') + b"\r\n" header_string += key.encode('utf-8') + b":" + v.encode('utf-8') + b"\r\n"
return compat.get_httpmessage(header_string) return compat.get_httpmessage(header_string)
def serialize_headers(response): def serialize_headers(response):
out = {} out = {}
for k, v in response.getheaders(): for key in response.msg.keys():
out.setdefault(k, []).append(v) out.setdefault(key, [])
out[key].extend(response.msg.getheaders(key))
return out return out