Skip to content

Commit e024a28

Browse files
specify how we handle 200 OK and interpret 405 as no range requests
1 parent a240a02 commit e024a28

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/pip/_internal/network/lazy_wheel.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ def _try_initial_chunk_request(self, initial_chunk_size: int) -> tuple[int, byte
279279
raise HTTPRangeRequestUnsupported(
280280
"returned complete file contents instead of range"
281281
)
282+
# According to MDN at
283+
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests, a 200 OK
284+
# implies that range requests are not supported, regardless of the requested
285+
# size. We have decided to allow servers to respond with 200 OK if the file
286+
# size was less than or equal to requested, even if this is nonstandard.
282287
elif code != codes.partial_content:
283288
raise HTTPRangeRequestUnsupported(
284289
"did not receive partial content or ok: got code {code}"
@@ -303,7 +308,7 @@ def _extract_content_length(
303308
resp = e.response
304309
code = resp.status_code
305310
# Our initial request using a negative byte range was not supported.
306-
if code == codes.not_implemented:
311+
if code in [codes.not_implemented, codes.method_not_allowed]:
307312
# pypi notably does not support negative byte ranges: see
308313
# https://github.com/pypi/warehouse/issues/12823.
309314
logger.debug(

0 commit comments

Comments
 (0)