Skip to content

fix(npm): respect etag for npm packument caching #29130

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

Merged
merged 5 commits into from
May 2, 2025

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented May 1, 2025

Stores the etag in a _deno.etag property on the json object of the packument.

Closes #24566

@dsherret dsherret changed the title fix: respect etag for npm packument caching fix(npm): respect etag for npm packument caching May 1, 2025
@dsherret dsherret marked this pull request as ready for review May 1, 2025 23:40
@dsherret dsherret requested a review from Copilot May 1, 2025 23:40
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes npm packument caching by respecting ETag headers. It computes an ETag for registry JSON files using a SHA256 hash (encoded in Base64) and returns a 304 Not Modified response when the “If-None-Match” header matches the computed ETag.

  • Introduced ETag computation and checking in the npm registry server.
  • Updated cache structures and HTTP client interfaces in the npm_cache resolvers.
  • Renamed and adjusted authentication header helper functions for consistency.

Reviewed Changes

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

Show a summary per file
File Description
tests/util/server/src/servers/npm_registry.rs Added ETag computation and response handling based on the “If-None-Match” header.
resolvers/npm_cache/tarball.rs Updated FTP traits and HTTP client call to handle the new ETag logic.
resolvers/npm_cache/remote.rs Renamed and simplified the auth header helper to return a raw string value.
resolvers/npm_cache/registry_info.rs Introduced a new SerializedCachedPackageInfo struct with a _deno.etag property.
resolvers/npm_cache/lib.rs Adjusted HTTP client response types and updated download logic to accommodate ETag.
cli/* Minor adaptations to propagate the updated HTTP client and caching API changes.
Files not reviewed (3)
  • tests/specs/npm/packument_etag/test.jsonc: Language not supported
  • tests/specs/npm/packument_etag/install_reload.out: Language not supported
  • tests/specs/npm/packument_etag/package.json: Language not supported

@dsherret dsherret requested review from bartlomieju and nathanwhit May 2, 2025 00:01
Comment on lines +323 to +324
// todo(dsherret): deserialize in a blocking task
serde_json::from_slice(&file_bytes)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you want to do it in a blocking task? If so, should it be done in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we can parallelize it like we do elsewhere. I want to see and measure its affects in a followup pr.

@dsherret dsherret merged commit 539e41b into denoland:main May 2, 2025
18 checks passed
@dsherret dsherret deleted the fix_use_etag_npm_caching branch May 2, 2025 13:49
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.

Use etag for npm packument
2 participants