diff --git a/src/runner/LightRunClient.ts b/src/runner/LightRunClient.ts index 95870cf..1615476 100644 --- a/src/runner/LightRunClient.ts +++ b/src/runner/LightRunClient.ts @@ -66,7 +66,7 @@ export class LightRunClient { if (!lightRunId) return; fetch(`${this.url}/runs/${lightRunId}/cancel`, { method: 'POST', - headers: this.headers(), + headers: this.authHeaders(), }).catch(() => {}); }; @@ -236,7 +236,7 @@ export class LightRunClient { async deleteNetwork(name: string): Promise { const res = await fetch(`${this.url}/networks/${encodeURIComponent(name)}`, { method: 'DELETE', - headers: this.headers(), + headers: this.authHeaders(), }); if (!res.ok && res.status !== 404) { const text = await res.text().catch(() => ''); @@ -278,7 +278,7 @@ export class LightRunClient { async stopRun(id: string): Promise { const res = await fetch(`${this.url}/runs/${id}/stop`, { method: 'POST', - headers: this.headers(), + headers: this.authHeaders(), }); if (!res.ok && res.status !== 404) { const text = await res.text().catch(() => ''); @@ -291,4 +291,17 @@ export class LightRunClient { if (this.token) h.authorization = `Bearer ${this.token}`; return h; } + + /* + * Headers for a request with NO body (stop, cancel, network delete). A + * bodyless request must not declare `content-type: application/json`: Fastify + * rejects an empty body under that content-type with 400 + * (FST_ERR_CTP_EMPTY_JSON_BODY), which silently failed service/network + * teardown. Carry only the bearer token. + */ + private authHeaders(): Record { + const h: Record = {}; + if (this.token) h.authorization = `Bearer ${this.token}`; + return h; + } }