Artifactspublic-v0

ply

main
ply4 git calls46 ms40 KiB3 cachedprotocol v2
63 lines4.4 KiBRaw
1// Fault-injection proxy in front of the real git server. The fault decision is a pure function of the
2// exchange context: fault(ctx) → spec. ctx = { stage: 'ls-refs'|'fetch'|'receive-pack', n (index within stage),
3// i (global index), status, headers, bytes (upstream body), reqBody }.
4// spec: { type: 'pass' } | { type: 'bytes', bytes, chunks? } | { type: 'status', status, body?, contentType? }
5// | { type: 'stall' } | { type: 'drop', after? } | { type: 'slow', chunk, delayMs }
6import http from 'node:http';
8export function startProxy(upstreamUrl, fault) {
9 const up = new URL(upstreamUrl);
10 const counts = {};
11 let i = 0;
12 const log = [];
13 const server = http.createServer((req, res) => {
14 const reqChunks = [];
15 req.on('data', d => reqChunks.push(d));
16 req.on('end', () => {
17 const reqBody = Buffer.concat(reqChunks);
18 const stage = req.url.endsWith('git-receive-pack') ? 'receive-pack' : /command=ls-refs/.test(reqBody.subarray(0, 40).toString()) ? 'ls-refs' : 'fetch';
19 const n = counts[stage] = (counts[stage] ?? 0) + 1;
20 const ctx = { stage, n: n - 1, i: i++, reqBody, headers: req.headers };
21 // a fault may answer without forwarding anything upstream (server never saw the request)
22 let pre = null;
23 try { pre = fault({ ...ctx, phase: 'request', bytes: new Uint8Array(0) }); } catch { pre = null; } // faults that need the upstream bytes are called later
24 if (pre && pre.type === 'bytes' && pre.noForward) {
25 log.push({ stage, n: ctx.n, spec: 'bytes(noForward)', detail: pre.name ?? '' });
26 Promise.resolve(pre.bytes).then(b => { res.writeHead(pre.status ?? 200, { 'content-type': pre.contentType ?? `application/x-${stage === 'receive-pack' ? 'git-receive-pack' : 'git-upload-pack'}-result` }); res.end(Buffer.from(b)); });
27 return;
28 }
29 const upReq = http.request({ host: up.hostname, port: up.port, path: req.url, method: req.method, headers: { ...req.headers, host: up.host } }, upRes => {
30 const chunks = [];
31 upRes.on('data', d => chunks.push(d));
32 upRes.on('end', async () => {
33 const bytes = new Uint8Array(Buffer.concat(chunks));
34 const spec = fault({ ...ctx, status: upRes.statusCode, headers: upRes.headers, bytes }) ?? { type: 'pass' };
35 if (spec.bytes && typeof spec.bytes.then === 'function') spec.bytes = await spec.bytes;
36 log.push({ stage, n: ctx.n, spec: spec.type, detail: spec.name ?? '' });
37 const hdrs = { 'content-type': upRes.headers['content-type'] ?? 'application/octet-stream', 'cache-control': 'no-cache' };
38 switch (spec.type) {
39 case 'pass': res.writeHead(upRes.statusCode, hdrs); res.end(Buffer.from(bytes)); break;
40 case 'bytes': {
41 res.writeHead(spec.status ?? upRes.statusCode, { ...hdrs, ...(spec.contentType ? { 'content-type': spec.contentType } : {}) });
42 const b = Buffer.from(spec.bytes);
43 if (spec.chunks) { let o = 0; for (const c of spec.chunks) { if (o >= b.length) break; res.write(b.subarray(o, o + c)); o += c; await new Promise(r => setTimeout(r, spec.delayMs ?? 0)); } res.write(b.subarray(o)); res.end(); }
44 else res.end(b);
45 break;
46 }
47 case 'status': res.writeHead(spec.status, { 'content-type': spec.contentType ?? 'text/html' }); res.end(spec.body ?? '<html>login</html>'); break;
48 case 'stall': res.writeHead(upRes.statusCode, hdrs); if (spec.partial) res.write(Buffer.from(bytes.subarray(0, spec.partial))); /* never end */ break;
49 case 'drop': { res.writeHead(upRes.statusCode, hdrs); if (spec.after) res.write(Buffer.from(bytes.subarray(0, spec.after))); res.destroy(); break; }
50 case 'slow': { res.writeHead(upRes.statusCode, hdrs); const b = Buffer.from(bytes); for (let o = 0; o < b.length; o += spec.chunk) { res.write(b.subarray(o, o + spec.chunk)); await new Promise(r => setTimeout(r, spec.delayMs)); } res.end(); break; }
51 default: throw new Error(`bad fault spec ${spec.type}`);
52 }
53 });
54 });
55 upReq.on('error', () => { res.writeHead(502); res.end(); });
56 upReq.end(reqBody);
57 });
58 });
59 return new Promise(resolve => server.listen(0, '127.0.0.1', () => resolve({
60 url: `http://127.0.0.1:${server.address().port}`, log, counts,
61 close: () => new Promise(r => { server.closeAllConnections?.(); server.close(r); }),
62 })));
Diagnostics4 git calls · 46 ms
CallStatusSizeTime046 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020038 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=40
git.response.bytes=38434
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4
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=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=38434
git.pkt.payload.max=38339
git.sideband.band1.bytes=38338
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=63
git.pack.bytes=38338
git.pack.ofs_delta=0
git.pack.ref_delta=8
git.pack.chain.max=8
git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77
git.pack.full=55
Open pack map
fetch2001.7 KiB · hit40 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1721
git.response.cache=HIT
git.response.duration_ms=40
git.fetch.wants=2300d9f854d813a5464d351fc99e54254a99958f
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=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1721
git.pkt.payload.max=1700
git.sideband.band1.bytes=1699
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://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply.git
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e20ff7ce297f3b
Request
2606cad6…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format