Lines 179–195 at 88 (were 179–184 at 87)
183+ * Every request this Api makes goes through here. In a visitor folder it never sends anything but a GET, 184+ * and follows no redirect, so nothing it sends goes anywhere it didn't name (headers() adds no sign-in). 186+ send(url: string, init: RequestInit = {}): Promise<Response> { 187+ if (!this.config.visitor) return fetch(url, init); 188+ if ((init.method ?? "GET") !== "GET") 189+ return Promise.reject(new ApiError("a folder that reads signed out sends only reads")); 190+ return fetch(url, { ...init, redirect: "error" }); 183194 method: "GET" | "POST", Lines 198–205 at 88 (were 187–195 at 87)
189200 let res: Response | undefined; 190− // A visitor folder only reads, and follows no redirect, so nothing it sends goes anywhere it didn't name.
191− const visitor = this.config.visitor === true;
192− if (visitor && method !== "GET") throw new ApiError(`${path}: a folder that reads signed out sends only reads`);
201+ if (this.config.visitor && method !== "GET") 202+ throw new ApiError(`${path}: a folder that reads signed out sends only reads`); 193203 const sent = body === undefined ? undefined : JSON.stringify(body); 194204 const timeoutMs = Math.max(atLeastMs, timeoutFor(this.timeoutMs, sent)); 195205 // A connection that never opened is tried once more, IPv4 first (#37, GAME - UI/UX: one IPv6 Lines 207–216 at 88 (were 197–207 at 87)
197207 // a POST is as safe to send again as a GET. 198208 for (let attempt = 0; res === undefined; attempt++) { 200− res = await fetch(this.url(path, server), {
210+ res = await this.send(this.url(path, server), { 202212 headers: this.headers(sent === undefined ? undefined : "application/json"), 203213 ...(sent === undefined ? {} : { body: sent }), 204− ...(visitor ? { redirect: "error" as const } : {}),
205214 signal: AbortSignal.timeout(timeoutMs), Lines 299–305 at 88 (were 290–296 at 87)
291300 let res: Response; 293− res = await fetch(`${this.url("/serve")}?${q}`, {
302+ res = await this.send(`${this.url("/serve")}?${q}`, { 295304 headers: this.headers(), 296305 signal: AbortSignal.timeout(20 * 60_000), Lines 320–335 at 88 (were 311–323 at 87)
311320 async prep(command: string, tarGz: Uint8Array<ArrayBuffer>): Promise<PrepAnswer> { 312321 let res: Response; 314− res = await fetch(`${this.url(this.agentPath("prep"))}?cmd=${encodeURIComponent(command)}${boxQuery(this.box)}`, {
315− method: "POST",
316− headers: this.headers("application/gzip"),
317− body: tarGz,
318− // A setup command can take minutes (npm ci, a browser download).
319− signal: AbortSignal.timeout(30 * 60_000),
320− });
323+ res = await this.send( 324+ `${this.url(this.agentPath("prep"))}?cmd=${encodeURIComponent(command)}${boxQuery(this.box)}`, 327+ headers: this.headers("application/gzip"), 329+ // A setup command can take minutes (npm ci, a browser download). 330+ signal: AbortSignal.timeout(30 * 60_000), 322334 const e = err as Error; 323335 throw new ApiError( Lines 345–351 at 88 (were 333–339 at 87)
333345 async unprep(): Promise<boolean> { 334346 let res: Response; 336− res = await fetch(
348+ res = await this.send( 337349 `${this.url(this.agentPath("prep"))}${this.box ? `?box=${encodeURIComponent(this.box)}` : ""}`, 338350 { method: "DELETE", headers: this.headers(), signal: AbortSignal.timeout(this.timeoutMs) }, Lines 381–387 at 88 (were 369–375 at 87)
369381 async bytes(method: "GET" | "PUT", path: string, body?: Uint8Array): Promise<Uint8Array> { 370382 let res: Response; 372− res = await fetch(this.url(path), {
384+ res = await this.send(this.url(path), { 374386 headers: this.headers(body === undefined ? undefined : "application/octet-stream"), 375387 ...(body === undefined ? {} : { body: body as Uint8Array<ArrayBuffer> }), Lines 503–509 at 88 (were 491–497 at 87)
491503 const path = this.agentPath("attachments"); 492504 let res: Response; 494− res = await fetch(this.url(path, this.issuesServer), {
506+ res = await this.send(this.url(path, this.issuesServer), { 496508 headers: { ...this.headers("application/octet-stream"), "x-abso-name": encodeURIComponent(name) }, 497509 body: bytes as Uint8Array<ArrayBuffer>, Lines 550–556 at 88 (were 538–544 at 87)
538550 const url = `${this.attachmentUrl(id)}${source ? "/source" : ""}`; 539551 let res: Response; 541− res = await fetch(url, {
553+ res = await this.send(url, { 542554 headers: this.headers(), 543555 signal: AbortSignal.timeout(Math.max(this.timeoutMs, 120_000)), Lines 948–954 at 88 (were 936–942 at 87)
936948 async logs(id: string, io: RunIO): Promise<number> { 937949 let res: Response; 939− res = await fetch(followUrl(this, id, { at: 0, errAt: 0 }), { headers: this.headers() });
951+ res = await this.send(followUrl(this, id, { at: 0, errAt: 0 }), { headers: this.headers() }); 941953 const e = err as Error; 942954 throw new ApiError(