Add conditional-request support to PyPI metadata APIs - #1341
Open
dkliban wants to merge 1 commit into
Open
Conversation
Member
|
@dkliban Please tag me as a reviewer once this is ready (maybe it already is?) |
jobselko
reviewed
Aug 21, 2026
Member
There was a problem hiding this comment.
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)) | |||
Member
There was a problem hiding this comment.
The issue mixes max-age=300 and max-age=600 for Simple endpoint. Is max-age=600 the value you want?
Member
Author
There was a problem hiding this comment.
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.
jobselko
reviewed
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
force-pushed
the
1338-conditional-requests
branch
from
August 21, 2026 19:19
9f0ef76 to
e842c0a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
Last-Modified/If-Modified-Sinceconditional request support to the Simple API and JSON Metadata API for improved cache efficiency. Also addsETag,Cache-Control, andIf-None-Matchsupport to the JSON Metadata API which previously had none.Changes:
_get_repo_version()helper to share repo version resolution between_etag_funcand new_last_modified_funclast_modified_func=_last_modified_functo@conditiondecorators onSimpleView.listandSimpleView.retrieve@condition(etag_func=_etag_func, last_modified_func=_last_modified_func)and@cache_control(max_age=900, public=True)toMetadataView.retrieveSecurity: Authorization is checked before conditional request handling because DRF's
initial()(permissions) runs before the view method where@conditionoperates.Closes: #1338
Test plan
test_simple_last_modified_header— Last-Modified present on Simple API responsestest_simple_if_modified_since_304— If-Modified-Since with matching timestamp returns 304test_simple_if_modified_since_old_timestamp_200— old timestamp returns 200test_metadata_conditional_request_headers— ETag, Last-Modified, Cache-Control on metadatatest_metadata_etag_conditional_request— If-None-Match 304/200test_metadata_if_modified_since_304— If-Modified-Since 304test_metadata_if_modified_since_old_timestamp_200— old timestamp returns 200test_unauthorized_gets_403_not_304— unauthorized client gets 403, not 304, with conditional headers