Skip to content

Commit a0b9562

Browse files
committed
Update stream.py
1 parent a49f8eb commit a0b9562

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/h2/stream.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,24 +1364,26 @@ def _initialize_content_length(self, headers: Iterable[Header]) -> None:
13641364
self._expected_content_length = 0
13651365
return
13661366

1367-
content_lengths = []
1367+
content_length = None
13681368

13691369
for n, v in headers:
13701370
if n == b"content-length":
13711371
try:
1372-
content_lengths.append(int(v, 10))
1372+
parsed_content_length = int(v, 10)
13731373
except ValueError as err:
13741374
msg = f"Invalid content-length header: {v!r}"
13751375
raise ProtocolError(msg) from err
13761376

1377-
if not content_lengths:
1378-
return
1377+
if content_length is None:
1378+
content_length = parsed_content_length
1379+
elif parsed_content_length != content_length:
1380+
msg = "Conflicting content-length headers"
1381+
raise ProtocolError(msg)
13791382

1380-
if len(set(content_lengths)) != 1:
1381-
msg = "Conflicting content-length headers"
1382-
raise ProtocolError(msg)
1383+
if content_length is None:
1384+
return
13831385

1384-
self._expected_content_length = content_lengths[0]
1386+
self._expected_content_length = content_length
13851387

13861388
def _track_content_length(self, length: int, end_stream: bool) -> None:
13871389
"""

0 commit comments

Comments
 (0)