Skip to content

Support PyPI Simple API JSON responses - #290

Open
andrew wants to merge 1 commit into
mainfrom
pypi-pep-691-json
Open

Support PyPI Simple API JSON responses#290
andrew wants to merge 1 commit into
mainfrom
pypi-pep-691-json

Conversation

@andrew

@andrew andrew commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Adds JSON content negotiation to the PyPI Simple API project list and package endpoints while keeping the legacy HTML default.

Rewrites JSON file URLs through the proxy, preserves upload timestamps, and isolates cached HTML and JSON representations. This allows uv exclude-newer to resolve packages through the proxy.

Fixes #282

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds PEP 691-style JSON content negotiation support to the PyPI Simple API endpoints served by the proxy, while preserving the legacy HTML default and ensuring cached representations are separated by negotiated media type.

Changes:

  • Selects an upstream Simple API representation based on the incoming Accept header (JSON/vendor HTML/legacy HTML) and adds Vary: Accept to responses.
  • Rewrites Simple API JSON responses to proxy file URLs and applies cooldown filtering in the JSON representation.
  • Adds/extends test coverage for negotiation behavior, cache separation, and cooldown behavior for Simple JSON.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/handler/pypi.go Implements Simple API content negotiation, Vary: Accept, representation-specific caching, and Simple JSON rewriting.
internal/handler/pypi_test.go Adds tests for representation selection, JSON negotiation, caching separation, and JSON cooldown filtering.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/handler/pypi.go
Comment on lines +167 to +171
switch mediaType {
case pypiSimpleJSON, pypiSimpleLatestJSON:
update(pypiSimpleJSON, quality, pypiExactSpecificity)
case pypiSimpleHTML, pypiSimpleLatestHTML:
update(pypiSimpleHTML, quality, pypiExactSpecificity)
Comment on lines +55 to +58
{"uv prefers json", uvPyPIAccept, pypiSimpleJSON},
{"json only", pypiSimpleJSON, pypiSimpleJSON},
{"latest json", pypiSimpleLatestJSON, pypiSimpleJSON},
{"vendor html", pypiSimpleHTML, pypiSimpleHTML},
@mj0nez

mj0nez commented Aug 27, 2026

Copy link
Copy Markdown

Looks good - tested with a local build. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(pypi): support PEP691 JSON API

3 participants