Repository navigation
Serve cached npm and Composer metadata gzip-compressed - #485
Merged
Merged
Conversation
- Keep a gzip copy of each rewrite cache entry when it is smaller, made once
per rewrite and counted against metadata_rewrite_cache_size
- Serve it with Content-Encoding: gzip to clients that accept gzip, with an
ETag of its own ("<sha256>-gzip") and Vary: Accept-Encoding
- Rewrites made outside the cache (cache disabled, cooldown on) stay
uncompressed
- rewriteCache.get and rewrite return rewrittenMetadata
andrew
approved these changes
Oct 15, 2026
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.
Problem
Rewritten npm and Composer metadata is sent uncompressed. With
npm_full_metadataon, a large packument is 10–16 MB (typescript: 15.8 MB,@types/node: 11.2 MB). Either clients download all of it, or a reverse proxy in front gzips the same document again on every request.Changes
Gzip copy in the rewrite cache (
rewrite_cache.go)metadata_rewrite_cache_sizeand typically adds about an eighth to an entry.Serving
Accept-Encodingallows gzip (gzip,x-gzipor*with q > 0) get the copy withContent-Encoding: gzip."<sha256>-gzip", so it never matches the uncompressed one. Both revalidate to304, also when a reverse proxy weakened the ETag.Vary: Accept-Encoding, 304s included.Unchanged
Last-Modifiedis the same for both representations.Cost
Go
compress/gzip, default level, once per distinct upstream document:typescript(full)@types/node(full)Verification
Built the proxy with
cache_metadataandnpm_full_metadataon:curl /npm/typescript: 2.0 MB withAccept-Encoding: gzip, 15.8 MB withidentity. Revalidating with the gzip ETag returns304.curl /composer/p2/symfony/http-kernel.json: 61 KB gzip, 542 KB identity.npm install typescript left-padandcomposer require symfony/http-kernelthrough the proxy both succeed.go test -race ./...andgolangci-lint run ./...pass.