Documentation
¶
Overview ¶
Package middleware provides HTTP middleware functions for Packhorse.
Index ¶
Constants ¶
const ( // HeaderGitalyCorrelationID is where GitLab Runner puts a job's correlation ID // on git HTTP requests. The runner sets it with // `git config http.extraHeader`, gated behind FF_USE_GITALY_CORRELATION_ID // (default true), and prints the same value in the job trace as // "Gitaly correlation ID: <id>". It is therefore the ID an operator has in hand // when a CI job fails with a git error. // // The value is the correlation ID of the runner's POST /api/v4/jobs/request // call — GitLab's X-Request-Id from that response, or a UUID the runner minted // itself if the response carried none. It is held on the job, so it stays // constant across every git request the job makes, including fetch retries. // // The runner spells it X-Gitaly-Correlation-ID on the wire. Written here in Go's // canonical form instead, which Header.Get and Header.Set both normalise to, so // the two match. HeaderGitalyCorrelationID = "X-Gitaly-Correlation-Id" )
Variables ¶
This section is empty.
Functions ¶
func AdoptGitalyCorrelationID ¶ added in v1.40.0
AdoptGitalyCorrelationID copies X-Gitaly-Correlation-ID into X-Request-Id when the request has no X-Request-Id of its own. The adopted value is deliberately not validated here, since CorrelationIDMiddleware validate it.
func Allowlist ¶
Allowlist wraps allowlist.Allowlist in a HTTP middleware. Requests for repositories not on the list are sent to fallback, which proxies them straight to the upstream without consulting the cache.
When list is nil or its disabled flag is set, every request flows through to next — see allowlist.Allowlist.Allowed.
func ProtocolV2 ¶
ProtocolV2 is HTTP middleware that enforces Git Protocol v2. It checks for the Git-Protocol header with value "version=2". Returns 400 Bad Request if missing or has different value.
This middleware should be applied to Git protocol routes but not to API routes that don't require Git protocol headers.
Types ¶
type DryRun ¶ added in v1.41.0
type DryRun struct {
// contains filtered or unexported fields
}
DryRun observes cache behaviour for repositories in the dry-run list without caching. Each git-upload-pack POST has its cache key computed and looked up in a shadow store that mirrors the real cache's sliding TTL; the coalescer detects concurrent identical requests. Metrics are emitted for would-be hit / miss / coalesce, and the request is unconditionally proxied to upstream via fallback. No packfiles are written to disk. Any request that is not an observable git-upload-pack POST, or whose repository is not in the dry-run list, is passed through to fallback unchanged.
The dry-run list reuses allowlist.Allowlist and asks "is this repo explicitly in the set" via list.Contains — the caching path's Allowed semantics (nil/disabled matches every repo) is the opposite of what dry-run wants.
func NewDryRun ¶ added in v1.41.0
func NewDryRun( list *allowlist.Allowlist, shadow *dryrun.Shadow, coalescer *coalesce.Coalescer, metrics observability.AppMetrics, fallback http.Handler, labelByRepo bool, ) *DryRun
NewDryRun builds a DryRun observer. labelByRepo should mirror list.Bounded() so per-repository metric cardinality is safe.