Skip to content
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

lazy-wheel: handle internal server error and others #9030

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 17 additions & 18 deletions src/poetry/inspection/lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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".
Expand Down
4 changes: 3 additions & 1 deletion tests/inspection/test_lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ def handle_request(
"negative_offset_error",
[
None,
(codes.not_found, b"Not found"), # Nexus
(codes.method_not_allowed, b"Method not allowed"),
(codes.requested_range_not_satisfiable, b"Requested range not satisfiable"),
(codes.not_implemented, b"Unsupported client range"),
(codes.internal_server_error, b"Internal server error"), # GAR
(codes.not_implemented, b"Unsupported client range"), # PyPI
(NEGATIVE_OFFSET_AS_POSITIVE, b"handle negative offset as positive"),
],
)
Expand Down
Loading