INNER CODE UNIT · TypeScript

appendSetCookie

namecheap/ilc · ilc/server/experiments/index.ts:49

function appendSetCookie(reply: ServerResponseFastifyReply, serialized: string): void {
    const existing = reply.raw.getHeader('Set-Cookie');
    if (existing === undefined) {
        reply.raw.setHeader('Set-Cookie', serialized);
    } else if (Array.isArray(existing)) {
        reply.raw.setHeader('Set-Cookie', [...existing, serialized]);
    } else {
        reply.raw.setHeader('Set-Cookie', [String(existing), serialized]);
    }
}

/**
 * Resolve experiment assignments for the request and propagate them:
 *  - into `ilcState.experiments` (inlined into the page and forwarded to fragments via appProps);
 *  - as `Set-Cookie` headers so the assignment is sticky across the session.
 *
 * Designed to be called from the ILC `onRequest` hook. It must run *after* i18n
 * so it appends to, rather than overwrites, any cookie i18n already set.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…