Skip to content

Commit 5c64648

Browse files
committed
Suggestions from review
1 parent 7c94aae commit 5c64648

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Lib/http/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ def send_head(self):
778778
if self._range:
779779
start, end = self._range
780780
if start is None:
781-
# parse_range() collapses (None, None) to None
781+
# parse_range() collapses (None, None) to None as it's invalid
782782
assert end is not None
783783
# `end` here means suffix length
784784
start = max(0, fs.st_size - end)
@@ -974,6 +974,8 @@ def parse_range(self):
974974
if range_header is None:
975975
return None
976976
m = RANGE_REGEX_PATTERN.match(range_header)
977+
# Ignore invalid Range header and return None
978+
# https://datatracker.ietf.org/doc/html/rfc9110#name-range
977979
if m is None:
978980
return None
979981

Lib/test/test_httpservers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,10 @@ def test_single_range_get_empty(self):
607607
self.assertEqual(response.getheader('content-range'), 'bytes */0')
608608
self.check_status_and_reason(response, HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE)
609609

610+
# invalid Range header is always ignored
611+
response = self.request(empty_path, headers={'Range': 'bytes=5-4'})
612+
self.check_status_and_reason(response, HTTPStatus.OK)
613+
610614
def test_multi_range_get(self):
611615
# multipart ranges (not supported currently)
612616
response = self.request(self.base_url + '/test', headers={'Range': 'bytes=1-2, 4-7'})

0 commit comments

Comments
 (0)