From 011a65d37488891f26896c461a51f82b73e93688 Mon Sep 17 00:00:00 2001 From: Danny McClanahan <1305167+cosmicexplorer@users.noreply.github.com> Date: Wed, 9 Aug 2023 00:59:28 -0400 Subject: [PATCH] specify how we handle 200 OK and interpret 405 as no range requests --- src/pip/_internal/network/lazy_wheel.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/network/lazy_wheel.py b/src/pip/_internal/network/lazy_wheel.py index b8a58d6e52d..41b322afb89 100644 --- a/src/pip/_internal/network/lazy_wheel.py +++ b/src/pip/_internal/network/lazy_wheel.py @@ -278,6 +278,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 requested, even if this is nonstandard. elif code != codes.partial_content: raise HTTPRangeRequestUnsupported( "did not receive partial content or ok: got code {code}" @@ -302,7 +307,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(