GitLabgitlab-org

cli

main
ply7 git calls349 ms98 KiB5 cachedprotocol v2
89 lines3.3 KiBRaw
1package proxy
3import (
4 "mime"
5 "net/http"
6 "strings"
7)
9// CompositeMatcher runs several ecosystem matchers against a request and
10// returns the first that recognizes it as in-scope. It lets one long-lived
11// proxy cover every supported ecosystem at once — as the job-level
12// `glab dependency-firewall job-proxy` does — instead of the per-run model where
13// each package-manager command installs a single ecosystem's matcher.
14//
15// The first Matched result wins and short-circuits, so a matcher that reads an
16// upload body is never run once an earlier matcher has already claimed the
17// request. A request no matcher claims passes straight through (Matched false),
18// exactly as a single matcher's non-match does.
19type CompositeMatcher []Matcher
21func (c CompositeMatcher) Match(req *http.Request) Match {
22 for _, m := range c {
23 if res := m.Match(req); res.Matched {
24 return res
25 }
26 }
27 return Match{}
30// DefaultMatchers returns one matcher per supported ecosystem, for a job-level
31// proxy that must recognize artifacts from any of them. The managers' own
32// Matcher() methods return these same zero-value structs; listing them once
33// here avoids running the npm (or PyPI) matcher several times for its family of
34// managers (npm/pnpm/yarn; pip/poetry/uv/twine/pipenv).
35func DefaultMatchers() CompositeMatcher {
36 return CompositeMatcher{
37 jsonPublishNPMMatcher{},
38 registryPathPyPIMatcher{},
39 MavenMatcher{},
40 GemMatcher{},
41 CargoMatcher{},
42 NuGetMatcher{},
43 }
46// registryPathPyPIMatcher is PyPIMatcher for a proxy that carries a whole job's
47// traffic. A bare sdist suffix (.tar.gz, .zip, .tgz, .tar.bz2) is common to any
48// archive, so on a job-wide proxy a plain curl of a toolchain tarball (for
49// example go.dev/dl/go1.22.3.linux-amd64.tar.gz) would be claimed as a PyPI
50// sdist and evaluated against a made-up coordinate; a transient API error on it
51// then fails the job closed. Claim a generic-archive download only when the path
52// carries a "/packages/" segment — the layout files.pythonhosted.org and the
53// GitLab PyPI registry both serve under. A .whl (and the twine upload POST) is
54// python-specific, so it is still claimed on any path.
55type registryPathPyPIMatcher struct{ PyPIMatcher }
57func (m registryPathPyPIMatcher) Match(req *http.Request) Match {
58 if req != nil && req.Method != http.MethodPost &&
59 hasGenericSdistExt(req.URL.Path) && !strings.Contains(req.URL.Path, "/packages/") {
60 return Match{}
61 }
62 return m.PyPIMatcher.Match(req)
65func hasGenericSdistExt(path string) bool {
66 for _, ext := range sdistExts {
67 if strings.HasSuffix(path, ext) {
68 return true
69 }
70 }
71 return false
74// jsonPublishNPMMatcher is NPMMatcher for a proxy that carries a whole job's
75// traffic. NPMMatcher reads the body of every PUT, which is right when only npm
76// is behind the proxy but would claim (and could block) any other upload in the
77// job, such as a Maven deploy, a cargo publish or a curl -T. npm, pnpm and yarn
78// send a publish as a JSON packument, so only a JSON PUT is inspected as one.
79type jsonPublishNPMMatcher struct{ NPMMatcher }
81func (m jsonPublishNPMMatcher) Match(req *http.Request) Match {
82 if req != nil && req.Method == http.MethodPut {
83 mediaType, _, err := mime.ParseMediaType(req.Header.Get("Content-Type"))
84 if err != nil || mediaType != "application/json" {
85 return Match{}
86 }
87 }
88 return m.NPMMatcher.Match(req)
Diagnostics7 git calls · 349 ms
CallStatusSizeTime0349 ms
discover200185 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0200361 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=361
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=506cba622ceda1473ee3cde63969809c144b7247
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=361
git.pkt.payload.max=334
git.sideband.band1.bytes=334
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=334
git.pack.trailer=26d32585a3a474717e00a318584ccd16918c9d32
Open pack map
fetchtree:02001.0 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=1051
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=7a2a90605315ba5b37f63c08726e6b2caa26e48d
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1051
git.pkt.payload.max=1024
git.sideband.band1.bytes=1024
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1024
git.pack.trailer=7503ef36a75d3595b473035c69e639fd0ce41598
Open pack map
fetch2001.6 KiB339 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=339
git.response.bytes=1591
git.response.cache=MISS
git.response.duration_ms=339
git.fetch.wants=8a586a04cbdfd34d401e6fdb142a0b5e22b6ee8e
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1591
git.pkt.payload.max=1564
git.sideband.band1.bytes=1564
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e259ba5da8a23e
Request
d70d951e…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format