Answer stability round 1: 2 🔴, 3 🟡 (0 misread); refuse a trailing-slash range, full plugin route, merged tests, compose passes TRUSTED_PROXIES

This commit is contained in:
2026-11-08 15:06:19 +01:00
parent 85219b081a
commit b19b43685c
10 changed files with 84 additions and 56 deletions
+5 -4
View File
@@ -4,7 +4,8 @@ import { type Log, requestLogger, runWithLog } from "../logger.ts";
import { requestFields, type TrustedProxies } from "./request-fields.ts";
// Gives one request its own logger and span, runs `handle` under it, and writes the `request` line
// when the response closes. The handler adds `http.route` to the logger's context once it knows it.
// when the response closes. The handler adds `http.route` to the logger's context once routing has
// matched.
export function trackRequest(
log: Log,
trusted: TrustedProxies,
@@ -12,8 +13,6 @@ export function trackRequest(
res: ServerResponse,
handle: (req: IncomingMessage, res: ServerResponse, reqLog: Log) => Promise<void>,
): void {
// "close" (not "finish") fires on both a completed response and a premature disconnect, so an
// aborted request is still logged and its span flushed.
const reqLog = requestLogger(log, {
attributes: requestFields(req, trusted),
requestId: randomUUID(),
@@ -25,10 +24,12 @@ export function trackRequest(
let settled = false;
let closed = false;
const finalize = (): void => { if (settled && closed) void reqLog.end().catch(() => {}); };
// "close" (not "finish") fires on both a completed response and a premature disconnect, so an
// aborted request is still logged and its span flushed.
res.on("close", () => {
closed = true;
try {
// The context is what the span exports, so the status goes there; the span's duration is the latency.
// The context is what the span exports, so the status goes there.
reqLog.context["http.response.status_code"] = res.statusCode;
reqLog.info("request");
} catch { /* never let logging crash a served request */ }