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
Improve test cases and code
  • Loading branch information
lyc8503 committed Jan 7, 2025
commit 42c69ab2ba39043622d60fa0db509e1ba25224b7
2 changes: 1 addition & 1 deletion Doc/library/http.server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ provides three different variants:

.. versionadded:: 3.2

.. method:: send_error(code, message=None, explain=None, *, extra_headers=None)
.. method:: send_error(code, message=None, explain=None, *, extra_headers=())

Sends and logs a complete error reply to the client. The numeric *code*
specifies the HTTP error code, with *message* as an optional, short, human
Expand Down
7 changes: 3 additions & 4 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def handle(self):
while not self.close_connection:
self.handle_one_request()

def send_error(self, code, message=None, explain=None, *, extra_headers=None):
def send_error(self, code, message=None, explain=None, *, extra_headers=()):
"""Send and log an error reply.

Arguments are
Expand Down Expand Up @@ -494,9 +494,8 @@ def send_error(self, code, message=None, explain=None, *, extra_headers=None):
body = content.encode('UTF-8', 'replace')
self.send_header("Content-Type", self.error_content_type)
self.send_header('Content-Length', str(len(body)))
if extra_headers is not None:
for name, value in extra_headers:
self.send_header(name, value)
for name, value in extra_headers:
self.send_header(name, value)
self.end_headers()

if self.command != 'HEAD' and body:
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_httpservers.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ def test_range_get(self):
response = self.request(route, headers={'Range': 'bytes=-'})
self.check_status_and_reason(response, HTTPStatus.OK, data=self.data)

response = self.request(route, headers={'Range': 'bytes=--'})
self.check_status_and_reason(response, HTTPStatus.OK, data=self.data)

response = self.request(route, headers={'Range': 'bytes='})
self.check_status_and_reason(response, HTTPStatus.OK, data=self.data)

# multipart ranges (not supported currently)
response = self.request(route, headers={'Range': 'bytes=1-2, 4-7'})
self.check_status_and_reason(response, HTTPStatus.OK, data=self.data)
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy