From 3082970ced1195709c6f24171869a24b2fcf6ca8 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 2 Oct 2025 11:54:35 -0700 Subject: [PATCH] Fix: Use robust JSON helper for header handling --- functions/api/user.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/functions/api/user.js b/functions/api/user.js index 3220974..e69fce6 100644 --- a/functions/api/user.js +++ b/functions/api/user.js @@ -1,8 +1,12 @@ -const json = (d, o) => new Response(JSON.stringify(d), { ...o, headers: { 'Content-Type': 'application/json', ...(o?.headers || {}) } }); +const json = (d, o = {}) => { + const h = new Headers(o.headers); + h.set('Content-Type', 'application/json'); + return new Response(JSON.stringify(d), { ...o, headers: h }); +}; const cookie = c => (c.match(/auth_user=([^;]+)/)?.[1] || null); const hash = c => (c.match(/auth_hash=([^;]+)/)?.[1] || null); const tsEq=(a,b)=>{if(!a||!b)return!1;let d=a.length^b.length;for(let i=0;i{const o=`Domain=.speech.capital; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT`;return {'Set-Cookie':`auth_user=; ${o}`,'Set-Cookie':`auth_hash=; ${o}`}}; +const clear = ()=>{const o=`Domain=.speech.capital; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT`;const h=new Headers();h.append('Set-Cookie',`auth_user=; ${o}`);h.append('Set-Cookie',`auth_hash=; ${o}`);return h}; export async function onRequest({ request, env }) { const c = request.headers.get('Cookie') || '';