Skip to content

Add conditional-request support to PyPI metadata APIs - #1341

Open
dkliban wants to merge 1 commit into
pulp:mainfrom
dkliban:1338-conditional-requests
Open

Add conditional-request support to PyPI metadata APIs#1341
dkliban wants to merge 1 commit into
pulp:mainfrom
dkliban:1338-conditional-requests

Conversation

@dkliban

@dkliban dkliban commented Aug 20, 2026

Copy link
Copy Markdown
Member

Summary

Add Last-Modified / If-Modified-Since conditional request support to the Simple API and JSON Metadata API for improved cache efficiency. Also adds ETag, Cache-Control, and If-None-Match support to the JSON Metadata API which previously had none.

Changes:

  • Extract _get_repo_version() helper to share repo version resolution between _etag_func and new _last_modified_func
  • Add last_modified_func=_last_modified_func to @condition decorators on SimpleView.list and SimpleView.retrieve
  • Add @condition(etag_func=_etag_func, last_modified_func=_last_modified_func) and @cache_control(max_age=900, public=True) to MetadataView.retrieve

Security: Authorization is checked before conditional request handling because DRF's initial() (permissions) runs before the view method where @condition operates.

Closes: #1338

Test plan

  • test_simple_last_modified_header — Last-Modified present on Simple API responses
  • test_simple_if_modified_since_304 — If-Modified-Since with matching timestamp returns 304
  • test_simple_if_modified_since_old_timestamp_200 — old timestamp returns 200
  • test_metadata_conditional_request_headers — ETag, Last-Modified, Cache-Control on metadata
  • test_metadata_etag_conditional_request — If-None-Match 304/200
  • test_metadata_if_modified_since_304 — If-Modified-Since 304
  • test_metadata_if_modified_since_old_timestamp_200 — old timestamp returns 200
  • test_unauthorized_gets_403_not_304 — unauthorized client gets 403, not 304, with conditional headers
  • All 4 existing cache tests still pass

@jobselko

Copy link
Copy Markdown
Member

@dkliban Please tag me as a reviewer once this is ready (maybe it already is?)

@dkliban
dkliban requested a review from jobselko August 20, 2026 17:16

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also test that an unauthorized client get 403 instead of 304?

@@ -379,7 +394,7 @@ def parse_package(release_package):

@extend_schema(operation_id="pypi_simple_package_read", summary="Get package simple page")
@method_decorator(cache_control(max_age=600, public=True))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue mixes max-age=300 and max-age=600 for Simple endpoint. Is max-age=600 the value you want?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max-age=600 is the pre-existing value on the Simple endpoints — this PR did not change it. The issue text proposed 300 but I intentionally kept 600 to avoid a behavioral change outside the scope of this feature.

Comment thread CHANGES/1338.feature Outdated
@github-actions github-actions Bot added the multi-commit Add to bypass single commit lint check label Aug 21, 2026
Add Last-Modified header and If-Modified-Since handling to SimpleView
and MetadataView for Akamai Centralized Authorization. Add ETag,
Cache-Control, and conditional request support to MetadataView which
previously had none.

Closes: pulp#1338
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dkliban
dkliban force-pushed the 1338-conditional-requests branch from 9f0ef76 to e842c0a Compare August 21, 2026 19:19
@github-actions github-actions Bot removed the multi-commit Add to bypass single commit lint check label Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add conditional-request support (ETag + Last-Modified) to PyPI metadata APIs for Akamai Centralized Authorization

2 participants