Help us shape the future of Go! Take the 2026 Go Developer Survey

composerproxy

package
v0.2.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package composerproxy implements proxies.CacheProxy for PHP Composer.

It is a pull-through cache for the Packagist metadata repository and the distribution archives that metadata points at.

INTERCEPTION

Composer honours COMPOSER_REPO_PACKAGIST, so pointing every job container at this proxy is a single env var — no workflow change, and a build off-fleet keeps working because the variable is simply absent.

WHAT IS CACHED

Metadata (packages.json and the per-package p2/<vendor>/<name>.json files) is MUTABLE: a package gains a version on every release. It is cached with a short TTL and then revalidated with a conditional GET, so a release published minutes ago is never invisible for long and an unchanged document costs one 304 — the same treatment the npm and pip proxies give their index documents.

Distribution archives are IMMUTABLE and are the bytes that actually matter. A Packagist dist URL names an exact commit:

https://api.github.com/repos/<vendor>/<pkg>/zipball/<40-char sha>

A given SHA cannot come back with different contents, so archives are cached permanently and never revalidated.

WHY DIST URLS ARE REWRITTEN

This is the difference between a cache that saves seconds and one that saves the download. The previous implementation of this proxy cached metadata only and said so plainly: "distribution zips come from mirrors and GitHub, which this proxy does not front". That leaves Composer taking a few kilobytes of JSON from the LAN and every megabyte of actual code from the WAN, on every job.

So each dist URL in a metadata document is rewritten to this proxy's archive route, exactly as the pip proxy rewrites the file links on a project page. Everything else in the document is left alone: rewriting is done on decoded JSON rather than by string replacement, because a blind substitution would also corrupt homepage/source/support fields that merely look like URLs.

Index

Constants

View Source
const (
	// DefaultUpstream is the Packagist metadata repository.
	DefaultUpstream = "https://repo.packagist.org"

	// DefaultMetadataTTL is how long a metadata document is served before it
	// is revalidated. Matches the npm/pip index default.
	DefaultMetadataTTL = 5 * time.Minute

	// DefaultPort continues the sequence npm 8084, pip 8085, pub 8086,
	// ghrel 8087.
	DefaultPort = 8088
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// CacheDir is the on-disk cache root (e.g. <data>/cache/composer).
	CacheDir string
	// Upstream overrides the Packagist metadata repository.
	Upstream string
	// ListenAddr is the address to bind and advertise.
	ListenAddr string
	// MetadataTTL is the revalidation interval for metadata documents.
	// Zero takes DefaultMetadataTTL; negative revalidates every request.
	MetadataTTL time.Duration
	// MaxBytes is the cache disk budget.
	MaxBytes int64
	// AllowedHosts extends the archive-fetch allowlist.
	AllowedHosts []string
	// Cleanup wipes the cache on Stop. Default false.
	Cleanup bool
	Log     *slog.Logger
}

Config configures the proxy.

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy is the Packagist caching proxy.

func New

func New(cfg Config) (*Proxy, error)

New creates a Composer caching proxy. Call Start() to begin serving.

func (*Proxy) Addr

func (p *Proxy) Addr() string

Addr returns the bound address.

func (*Proxy) EnvVars

func (p *Proxy) EnvVars() []string

EnvVars points Composer at this proxy.

func (*Proxy) Healthy

func (p *Proxy) Healthy() bool

Healthy reports whether the proxy is serving.

func (*Proxy) Name

func (p *Proxy) Name() string

Name returns the proxy name for logs.

func (*Proxy) Start

func (p *Proxy) Start() error

Start begins serving. Returns after the listener is bound.

func (*Proxy) Stop

func (p *Proxy) Stop() error

Stop shuts the proxy down.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL