gitoria
All repositories: gitoria
2.1 KB
// lib/transport-helpers.hl — what lib/transport.hl looks up: the Basic password of a request, the plain-text answers,// the protocol version a client asks for, git's pkt-line. Statics only.import { Response } from 'hl:http1'import { run } from 'hl:proc'import { NL, isBase64 } from './util.hl'// the password of a Basic `Authorization` header ('user:password' → 'password'); null without one.// Hybriel has no base64 decoder (hybriel ticket candidate), so `base64 -d` decodes it — the text goes in as an// argument, after a check that it only holds base64 characters.static passwordOf = (header) => {if (header == null || hlTypeName(header) != 'String') { return null }h = header.trim()if (h.length < 7 || h.slice(0, 6).toLowerCase() != 'basic ') { return null }b = h.slice(6).trim()if (!isBase64(b, 600)) { return null }r = run(['sh', '-c', 'printf %s "$1" | base64 -d 2>/dev/null', 'sh', b], { timeout = 10 })if (r == null || r.exit != 0 || r.lines.length == 0) { return null }text = r.lines[0]colon = text.indexOf(':')return colon < 0 ? null : text.slice(colon + 1)}static plain = (status, text, extra) => {let headers = { 'Content-Type' = 'text/plain; charset=utf-8' 'Cache-Control' = 'no-store' 'X-Content-Type-Options' = 'nosniff' }if (extra != null) { for (k of extra.keys()) { headers[k] = extra[k] } }return new Response(text + NL, { status = status headers = headers })}// git speaks protocol v2 when the client says so: `Git-Protocol: version=2` (only that shape is passed on)static protocolEnv = (req) => {v = req.headers['git-protocol']if (v == null || hlTypeName(v) != 'String' || v.length > 40) { return {} }let ok = v.length > 0let i = 0while (i < v.length) {c = v.charCodeAt(i)if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 122) || c == 61 || c == 58)) { ok = false }i = i + 1}return ok ? { GIT_PROTOCOL = v } : {}}// pkt-line: 4 hex digits of the length (itself included), then the textstatic pktLine = (text) => {let n = text.length + 4hex = '0123456789abcdef'let out = ''let i = 0while (i < 4) {d = n % 16out = hex[d] + outn = (n - d) / 16i = i + 1}return out + text}
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 26117255|||PR apps API: review comments on files with spaces in their namemre
- b8796cecMerge branch 'f1-broken-json' into mainGitoria
- 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
- f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
- 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
- 16a3530fMerge branch 'heap-revert' into mainGitoria
- 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
- 13f0c342Merge branch 'hl25-records' into mainGitoria
- a002ecb7|||PR records: HL25 report, heap helper, logmre
- 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
- fefaedd2log: tracker PR-only, HL25 startedmre
- 21aa57calog: parkmre
- e9f950a8reports: G25c soakmre
- a7783686log: deploy 9f41ffcmre
- 9f41ffc1log: W30b mergedmre
- bef635c1Merge branch 'w30b'mre
- 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
- c4f6d9e3reports: G25c growth huntmre
- b88e39f1log: privacy cleanup donemre
- bfd7826ddocs: neutral example organisation namemre