MediumPro challengePythonJavaScriptTypeScript

Serialize Set-Cookie

Node.jsHTTPCookies

Build a Set-Cookie header value from name, value, and options.

Options support: maxAge (number, seconds), httpOnly (bool),
secure (bool), sameSite ('Strict' | 'Lax' | 'None'), path (string).

Order: name=value; Max-Age=N; Path=/; HttpOnly; Secure; SameSite=Lax
(only include flags that are truthy / present).

Sample tests

Test #1Plain
Input: ["sid","abc"]
Output: "sid=abc"
Test #2Flags
Input: ["sid","abc",{"secure":true,"httpOnly":true}]
Output: "sid=abc; HttpOnly; Secure"
Test #3Numeric and path
Input: ["sid","abc",{"path":"/","maxAge":3600}]
Output: "sid=abc; Max-Age=3600; Path=/"
Test #4SameSite
Input: ["k","v",{"sameSite":"Lax"}]
Output: "k=v; SameSite=Lax"
Test #5All options
Input: ["a","b",{"path":"/x","maxAge":0,"secure":true,"httpOnly":true,"sameSite":"Strict"}]
Output: "a=b; Max-Age=0; Path=/x; HttpOnly; Secure; SameSite=Strict"