8000 gh-86809: Add support for HTTP Range header in HTTPServer by lyc8503 · Pull Request #118949 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-86809: Add support for HTTP Range header in HTTPServer #118949

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

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Suggestions from review
  • Loading branch information
lyc8503 committed Jan 13, 2025
commit 5c64648b3ef5a918169afb227b4f718214b37623
4 changes: 3 additions & 1 deletion Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def send_head(self):
if self._range:
start, end = self._range
if start is None:
# parse_range() collapses (None, None) to None
# parse_range() collapses (None, None) to None as it's invalid
assert end is not None
# `end` here means suffix length
start = max(0, fs.st_size - end)
Expand Down Expand Up @@ -974,6 +974,8 @@ def parse_range(self):
if range_header is None:
return None
m = RANGE_REGEX_PATTERN.match(range_header)
# Ignore invalid Range header and return None
# https://datatracker.ietf.org/doc/html/rfc9110#name-range
if m is None:
return None

Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_httpservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,10 @@ def test_single_range_get_empty(self):
self.assertEqual(response.getheader('content-range'), 'bytes */0')
self.check_status_and_reason(response, HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE)

# invalid Range header is always ignored
response = self.request(empty_path, headers={'Range': 'bytes=5-4'})
self.check_status_and_reason(response, HTTPStatus.OK)

def test_multi_range_get(self):
# multipart ranges (not supported currently)
response = self.request(self.base_url + '/test', headers={'Range': 'bytes=1-2, 4-7'})
Expand Down
Loading
0