ProvenPin Install

set-cookie-parser single and joined headers: working versions (tested 2026-10-16)

Parse single and array Set-Cookie headers with set-cookie-parser, split comma-joined headers using splitCookiesString, and assert name, value, path, httpOnly and sameSite fields offline.

passed3 passed · 0 failed2026-10-16 17:51 UTC
Status
passed
Last passed
2026-10-16 17:51 UTC
Tests
3 / 3
Language
TypeScript
Runtime
node v22.23.3
pinned versions4
set-cookie-parser@3.1.4@types/set-cookie-parser@2.4.10@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38942732901

The code

Exactly the files that passed. Your agent can pull them with get_recipe("set-cookie-parser-split") (install), or see them on GitHub.

package.json
{
  "name": "set-cookie-parser-split",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "set-cookie-parser": "3.1.4"
  },
  "devDependencies": {
    "@types/set-cookie-parser": "2.4.10",
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/cookies.ts
import setCookieParser from "set-cookie-parser";

export type ParsedCookie = {
  name: string;
  value: string;
  path?: string;
  httpOnly?: boolean;
  sameSite?: string | boolean;
};

export const splitCookiesString: (input: string) => string[] =
  setCookieParser.splitCookiesString;

export function parseOne(header: string): ParsedCookie {
  const cookies = setCookieParser.parse(header);
  const first = cookies[0];
  if (!first) {
    throw new Error("expected at least one cookie");
  }
  return first;
}

export function parseAll(headers: string | string[]): ParsedCookie[] {
  return setCookieParser.parse(headers);
}

export function parseJoined(header: string): ParsedCookie[] {
  const parts = setCookieParser.splitCookiesString(header);
  return setCookieParser.parse(parts);
}
test/cookies.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import {
  parseOne,
  parseAll,
  parseJoined,
  splitCookiesString,
} from "../src/cookies.ts";

test("parses a single Set-Cookie header", () => {
  const cookie = parseOne("session=abc123; Path=/; HttpOnly; SameSite=Lax");
  assert.equal(cookie.name, "session");
  assert.equal(cookie.value, "abc123");
  assert.equal(cookie.path, "/");
  assert.equal(cookie.httpOnly, true);
  assert.equal(String(cookie.sameSite).toLowerCase(), "lax");
});

test("parses an array of Set-Cookie headers", () => {
  const cookies = parseAll([
    "session=abc123; Path=/; HttpOnly; SameSite=Strict",
    "theme=dark; Path=/app; Max-Age=3600",
  ]);
  assert.equal(cookies.length, 2);

  const session = cookies[0]!;
  assert.equal(session.name, "session");
  assert.equal(session.value, "abc123");
  assert.equal(session.path, "/");
  assert.equal(session.httpOnly, true);
  assert.equal(String(session.sameSite).toLowerCase(), "strict");

  const theme = cookies[1]!;
  assert.equal(theme.name, "theme");
  assert.equal(theme.value, "dark");
  assert.equal(theme.path, "/app");
  assert.equal(theme.httpOnly, undefined);
});

test("splits comma-joined Set-Cookie headers with Expires dates", () => {
  const joined =
    "id=1; Path=/; Expires=Wed, 21 Oct 2026 07:28:00 GMT, token=xyz; Path=/; HttpOnly; SameSite=None";

  const parts = splitCookiesString(joined);
  assert.equal(parts.length, 2);
  assert.equal(parts[0], "id=1; Path=/; Expires=Wed, 21 Oct 2026 07:28:00 GMT");

  const cookies = parseJoined(joined);
  assert.equal(cookies.length, 2);
  assert.equal(cookies[0]!.name, "id");
  assert.equal(cookies[0]!.value, "1");
  assert.equal(cookies[0]!.path, "/");
  assert.equal(cookies[1]!.name, "token");
  assert.equal(cookies[1]!.value, "xyz");
  assert.equal(cookies[1]!.path, "/");
  assert.equal(cookies[1]!.httpOnly, true);
  assert.equal(String(cookies[1]!.sameSite).toLowerCase(), "none");
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.