From ec5bde758d8f045792630de1ebb1ae03bd56f261 Mon Sep 17 00:00:00 2001 From: shigahi Date: Thu, 22 Oct 2026 08:59:06 +0200 Subject: [PATCH] Forward compressed API request bodies unchanged The Notion client now gzips event batches sent to /api/v3/etClient. The worker read every API body as text and dropped Content-Encoding, so Notion rejected them with 400 invalid_json. Co-Authored-By: Claude Opus 5.5 --- src/code.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/code.ts b/src/code.ts index 79c08e3..572cab1 100644 --- a/src/code.ts +++ b/src/code.ts @@ -827,7 +827,7 @@ ${ 'user-agent': PAGE_FETCH_HEADERS['user-agent'] }; for (const [key, value] of request.headers) { - if (key.startsWith('x-notion-') || key.startsWith('notion-')) headers[key] = value; + if (key === 'content-encoding' || key.startsWith('x-notion-') || key.startsWith('notion-')) headers[key] = value; } return headers; } @@ -1001,8 +1001,11 @@ ${ response.headers.delete('Content-Security-Policy'); return response; } else if (url.pathname.startsWith('/api/')) { - // Rewrite request body: replace custom space domain with original Notion space domain - const reqBody = swapSpaceDomainInJson(await request.text(), CUSTOM_SPACE_DOMAIN, NOTION_SPACE_DOMAIN); + // Rewrite request body: replace custom space domain with original Notion space domain. + // Compressed bodies (the client's gzipped event batches) are forwarded as-is. + const reqBody = request.headers.has('content-encoding') + ? await request.arrayBuffer() + : swapSpaceDomainInJson(await request.text(), CUSTOM_SPACE_DOMAIN, NOTION_SPACE_DOMAIN); response = await fetch(url.toString(), { body: reqBody, headers: buildApiHeaders(request),