Skip to content

Commit 7da585b

Browse files
tomchristiepgjones
authored andcommitted
Lower change footprint
1 parent ce515c5 commit 7da585b

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

h11/_connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,27 +560,27 @@ def _clean_up_response_headers_for_sending(self, response):
560560
# but the HTTP spec says that if our peer does this then we have
561561
# to fix it instead of erroring out, so we'll accord the user the
562562
# same respect).
563-
headers = set_comma_header(headers, b"Content-Length", [])
563+
headers = set_comma_header(headers, b"content-length", [])
564564
if self.their_http_version is None or self.their_http_version < b"1.1":
565565
# Either we never got a valid request and are sending back an
566566
# error (their_http_version is None), so we assume the worst;
567567
# or else we did get a valid HTTP/1.0 request, so we know that
568568
# they don't understand chunked encoding.
569-
headers = set_comma_header(headers, b"Transfer-Encoding", [])
569+
headers = set_comma_header(headers, b"transfer-encoding", [])
570570
# This is actually redundant ATM, since currently we
571571
# unconditionally disable keep-alive when talking to HTTP/1.0
572572
# peers. But let's be defensive just in case we add
573573
# Connection: keep-alive support later:
574574
if self._request_method != b"HEAD":
575575
need_close = True
576576
else:
577-
headers = set_comma_header(headers, b"Transfer-Encoding", ["chunked"])
577+
headers = set_comma_header(headers, b"transfer-encoding", ["chunked"])
578578

579579
if not self._cstate.keep_alive or need_close:
580580
# Make sure Connection: close is set
581581
connection = set(get_comma_header(headers, b"connection"))
582582
connection.discard(b"keep-alive")
583583
connection.add(b"close")
584-
headers = set_comma_header(headers, b"Connection", sorted(connection))
584+
headers = set_comma_header(headers, b"connection", sorted(connection))
585585

586586
response.headers = headers

h11/_headers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,12 @@ def get_comma_header(headers, name):
170170

171171
def set_comma_header(headers, name, new_values):
172172
# The header name `name` is expected to be lower-case bytes.
173-
raw_name = name
174-
name = name.lower()
175173
new_headers = []
176174
for found_raw_name, found_name, found_raw_value in headers.raw_items:
177175
if found_name != name:
178176
new_headers.append((found_raw_name, found_raw_value))
179177
for new_value in new_values:
180-
new_headers.append((raw_name, new_value))
178+
new_headers.append((name.title(), new_value))
181179
return normalize_and_validate(new_headers)
182180

183181

0 commit comments

Comments
 (0)