Skip to content

Commit

Permalink
specify how we handle 200 OK and interpret 405 as no range requests
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Aug 9, 2023
1 parent d237759 commit 12c78b0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pip/_internal/network/lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ def _try_initial_chunk_request(self, initial_chunk_size: int) -> tuple[int, byte
raise HTTPRangeRequestUnsupported(
"returned complete file contents instead of range"
)
# According to MDN at
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests, a 200 OK
# implies that range requests are not supported, regardless of the requested
# size. We have decided to allow servers to respond with 200 OK if the file
# size was less than or equal to requested, even if this is nonstandard.
elif code != codes.partial_content:
raise HTTPRangeRequestUnsupported(
"did not receive partial content or ok: got code {code}"
Expand All @@ -303,7 +308,7 @@ def _extract_content_length(
resp = e.response
code = resp.status_code
# Our initial request using a negative byte range was not supported.
if code == codes.not_implemented:
if code in [codes.not_implemented, codes.method_not_allowed]:
# pypi notably does not support negative byte ranges: see
# https://github.com/pypi/warehouse/issues/12823.
logger.debug(
Expand Down

0 comments on commit 12c78b0

Please sign in to comment.