File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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' })
You can’t perform that action at this time.
0 commit comments