Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit ac32f85

Browse files
committed
Optional conversion to bytes.
1 parent 0c02064 commit ac32f85

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

hyper/http20/hpack.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ def decode_integer(data, prefix_bits):
7373
return (number, index + 1)
7474

7575

76+
def _to_bytes(string):
77+
"""
78+
Convert string to bytes.
79+
"""
80+
return string if isinstance(string, bytes) else string.encode('utf-8')
81+
82+
7683
def header_table_size(table):
7784
"""
7885
Calculates the 'size' of the header table as defined by the HTTP/2.0
@@ -227,7 +234,7 @@ def encode(self, headers, huffman=True):
227234
headers = headers.items()
228235

229236
# Next, walk across the headers and turn them all into bytestrings.
230-
headers = [(n.encode('utf-8'), v.encode('utf-8')) for n, v in headers]
237+
headers = [(_to_bytes(n), _to_bytes(v)) for n, v in headers]
231238

232239
incoming_set = set(headers)
233240

0 commit comments

Comments
 (0)