-
Notifications
You must be signed in to change notification settings - Fork 64
event.headers returns array of bytearray since 0.8.0 #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So like I noted over in the wsproto PR, it's probably some kind of bug in h11, but I can't seem to reproduce this behavior myself:
Can you give more details on what version of Python you're using? Do you have an example that demonstrates this? |
I can confirm that this issue only occurs on Python 2. |
@njsmith I found the cause. The validate function in _util.py causes the issue. I've gathered the related code here (run with python2 and python3 to see the differences in output): import re
request_line_re = re.compile("(?P<method>[-!#$%&'*+.^_`|~0-9a-zA-Z]+) (?P<target>[^ ]+) HTTP/(?P<http_version>[0-9]\\.[0-9])".encode("ascii"))
try:
_fullmatch = type(re.compile('')).fullmatch
except AttributeError:
def _fullmatch(regex, data): # version specific: Python < 3.4
match = regex.match(data)
if match and match.end() != len(data):
match = None
return match
def validate(regex, data, msg="malformed data", *format_args):
match = _fullmatch(regex, data)
if not match:
if format_args:
msg = msg.format(*format_args)
raise LocalProtocolError(msg)
test = match.groupdict()
return test
result = validate(request_line_re, bytearray(b'GET / HTTP/1.1'))
print(result) validate is called from |
In the process of upgrading wsproto to h11 0.8.0 I noticed that the _normed_header_dict method https://github.com/python-hyper/wsproto/blob/cbb93a34808cf4894914e91df81e99f957f2753d/wsproto/connection.py#L49 (which receives headers directly from h11 without any transformations as far as I'm aware) receives an array of strings when using h11 0.7.0 and an array of bytearrays when using h11 0.8.0 which breaks wsproto when using h11 0.8.0.
The text was updated successfully, but these errors were encountered: