Skip to content
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

No byteswarning #1290

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/h2/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ def __init__(self):
def __repr__(self):
return (
"<AlternativeServiceAvailable origin:%s, field_value:%s>" % (
self.origin.decode('utf-8', 'ignore'),
self.field_value.decode('utf-8', 'ignore'),
(self.origin or b'').decode('utf-8', 'ignore'),
(self.field_value or b'').decode('utf-8', 'ignore'),
)
)

Expand Down
11 changes: 9 additions & 2 deletions src/h2/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
from .utilities import (
guard_increment_window, is_informational_response, authority_from_headers,
validate_headers, validate_outbound_headers, normalize_outbound_headers,
HeaderValidationFlags, extract_method_header, normalize_inbound_headers
HeaderValidationFlags, extract_method_header, normalize_inbound_headers,
utf8_encode_headers
)
from .windows import WindowManager

Expand Down Expand Up @@ -851,6 +852,9 @@ def send_headers(self, headers, encoder, end_stream=False):
# we need to scan the header block to see if this is an informational
# response.
input_ = StreamInputs.SEND_HEADERS

headers = utf8_encode_headers(headers)

if ((not self.state_machine.client) and
is_informational_response(headers)):
if end_stream:
Expand Down Expand Up @@ -1240,6 +1244,9 @@ def _build_headers_frames(self,
"""
Helper method to build headers or push promise frames.
"""

headers = utf8_encode_headers(headers)

# We need to lowercase the header names, and to ensure that secure
# header fields are kept out of compression contexts.
if self.config.normalize_outbound_headers:
Expand Down Expand Up @@ -1319,7 +1326,7 @@ def _initialize_content_length(self, headers):
self._expected_content_length = int(v, 10)
except ValueError:
raise ProtocolError(
"Invalid content-length header: %s" % v
f"Invalid content-length header: {repr(v)}"
)

return
Expand Down
Loading
Loading