INNER CODE UNIT · TypeScript

tokenMatches

yvgude/lean-ctx · packages/vscode-lean-ctx/src/bridge/server.ts:17

function tokenMatches(expected: Buffer, got: string | string[] | undefined): boolean {
  if (typeof got !== "string") return false;
  const actual = Buffer.from(got);
  return actual.length === expected.length && timingSafeEqual(actual, expected);
}

function send(res: http.ServerResponse, status: number, body: unknown): void {
  const text = JSON.stringify(body);
  res.writeHead(status, {
    "Content-Type": "application/json",
    "Content-Length": Buffer.byteLength(text),
    Connection: "close",
  });
  res.end(text);
}

/**
 * Serves `root` on `127.0.0.1` (ephemeral port). Every request must carry

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…