File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed
Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,10 @@ def test_headers_raw_dict_none(self):
1919 self .assertIsNone (headers_dict_to_raw (None ))
2020
2121 def test_headers_raw_to_dict (self ):
22- raw = b"Content-type: text/html\n \r Accept: gzip\n \n "
23- dct = {b'Content-type' : [b'text/html' ], b'Accept' : [b'gzip' ]}
22+ raw = b"Content-type: text/html\n \r Accept: gzip\n \r \
23+ Cache-Control: no-cache\n \r Cache-Control: no-store\n \n "
24+ dct = {b'Content-type' : [b'text/html' ], b'Accept' : [b'gzip' ],
25+ b'Cache-Control' : [b'no-cache' , b'no-store' ]}
2426 self .assertEqual (headers_raw_to_dict (raw ), dct )
2527
2628 def test_headers_dict_to_raw (self ):
Original file line number Diff line number Diff line change @@ -29,11 +29,21 @@ def headers_raw_to_dict(headers_raw):
2929 return None
3030 headers = headers_raw .splitlines ()
3131 headers_tuples = [header .split (b':' , 1 ) for header in headers ]
32- return dict ([
33- (header_item [0 ].strip (), [header_item [1 ].strip ()])
34- for header_item in headers_tuples
35- if len (header_item ) == 2
36- ])
32+
33+ result_dict = {}
34+ for header_item in headers_tuples :
35+ if not len (header_item ) == 2 :
36+ continue
37+
38+ item_key = header_item [0 ].strip ()
39+ item_value = header_item [1 ].strip ()
40+
41+ if item_key in result_dict :
42+ result_dict [item_key ].append (item_value )
43+ else :
44+ result_dict [item_key ] = [item_value ]
45+
46+ return result_dict
3747
3848
3949def headers_dict_to_raw (headers_dict ):
You can’t perform that action at this time.
0 commit comments