diff --git a/src/poetry/inspection/lazy_wheel.py b/src/poetry/inspection/lazy_wheel.py index 885ea7166e5..54f566bb3c6 100644 --- a/src/poetry/inspection/lazy_wheel.py +++ b/src/poetry/inspection/lazy_wheel.py @@ -608,22 +608,10 @@ def _extract_content_length( # Initial range request for just the end of the file. file_length, tail = self._try_initial_chunk_request(initial_chunk_size) except HTTPError as e: + # Our initial request using a negative byte range was not supported. resp = e.response code = resp.status_code if resp is not None else None - # Our initial request using a negative byte range was not supported. - 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( - "Negative byte range not supported for domain '%s': " - "using HEAD request before lazy wheel from now on", - domain, - ) - # Avoid trying a negative byte range request against this domain for the - # rest of the resolve. - self._domains_without_negative_range.add(domain) - # Apply a HEAD request to get the real size, and nothing else for now. - return (self._content_length_from_head(), None) + # This indicates that the requested range from the end was larger than the # actual file size: https://www.rfc-editor.org/rfc/rfc9110#status.416. if code == codes.requested_range_not_satisfiable: @@ -633,10 +621,21 @@ def _extract_content_length( file_length = self._parse_full_length_from_content_range( resp.headers["Content-Range"] ) - return (file_length, None) - # If we get some other error, then we expect that non-range requests will - # also fail, so we error out here and let the user figure it out. - raise + return file_length, None + + # pypi notably does not support negative byte ranges: see + # https://github.com/pypi/warehouse/issues/12823. + logger.debug( + "Negative byte range not supported for domain '%s': " + "using HEAD request before lazy wheel from now on (code: %s)", + domain, + code, + ) + # Avoid trying a negative byte range request against this domain for the + # rest of the resolve. + self._domains_without_negative_range.add(domain) + # Apply a HEAD request to get the real size, and nothing else for now. + return self._content_length_from_head(), None # Some servers that do not support negative offsets, # handle a negative offset like "-10" as "0-10". diff --git a/tests/inspection/test_lazy_wheel.py b/tests/inspection/test_lazy_wheel.py index b32bdd48d4f..7eea30f33de 100644 --- a/tests/inspection/test_lazy_wheel.py +++ b/tests/inspection/test_lazy_wheel.py @@ -158,6 +158,7 @@ def handle_request( None, (codes.method_not_allowed, b"Method not allowed"), (codes.requested_range_not_satisfiable, b"Requested range not satisfiable"), + (codes.internal_server_error, b"Internal server error"), (codes.not_implemented, b"Unsupported client range"), (NEGATIVE_OFFSET_AS_POSITIVE, b"handle negative offset as positive"), ],