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

Commit 19e8472

Browse files
committed
Convert header name to native string before checking
1 parent 2c74d1a commit 19e8472

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

hyper/common/util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88
from hyper.compat import unicode, bytes, imap
99
from ..packages.rfc3986.uri import URIReference
10+
from ..compat import is_py3
1011
import re
1112

1213

@@ -50,3 +51,10 @@ def to_host_port_tuple(host_port_str, default_port=80):
5051
port = int(uri.port)
5152

5253
return (host, port)
54+
55+
56+
def to_native_string(string, encoding='utf-8'):
57+
if isinstance(string, str):
58+
return string
59+
60+
return string.decode(encoding) if is_py3 else string.encode(encoding)

hyper/http20/connection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ..common.exceptions import ConnectionResetError
1010
from ..common.bufsocket import BufferedSocket
1111
from ..common.headers import HTTPHeaderMap
12-
from ..common.util import to_host_port_tuple
12+
from ..common.util import to_host_port_tuple, to_native_string
1313
from ..packages.hyperframe.frame import (
1414
FRAMES, DataFrame, HeadersFrame, PushPromiseFrame, RstStreamFrame,
1515
SettingsFrame, Frame, WindowUpdateFrame, GoAwayFrame, PingFrame,
@@ -172,7 +172,8 @@ def request(self, method, url, body=None, headers={}):
172172

173173
default_headers = (':method', ':scheme', ':authority', ':path')
174174
for name, value in headers.items():
175-
self.putheader(name, value, stream_id, replace=name in default_headers)
175+
is_default = to_native_string(name) in default_headers
176+
self.putheader(name, value, stream_id, replace=is_default)
176177

177178
# Convert the body to bytes if needed.
178179
if isinstance(body, str):

0 commit comments

Comments
 (0)