From d14aae1bd35a68ed6836db6277753f2e3619de1b Mon Sep 17 00:00:00 2001 From: Geoff Rich <4992896+geoffrich@users.noreply.github.com> Date: Sat, 13 Jul 2024 16:58:23 -0700 Subject: [PATCH] fix: work around SWA issue with empty form bodies (#179) * fix: work around SWA issue with empty form bodies * chore: more debug logs --- files/entry.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/files/entry.js b/files/entry.js index 857ce44..2ae126e 100644 --- a/files/entry.js +++ b/files/entry.js @@ -29,6 +29,12 @@ export async function index(context) { const request = toRequest(context); if (debug) { + context.log( + 'Starting request', + context?.req?.method, + context?.req?.headers?.['x-ms-original-url'] + ); + context.log(`Original request: ${JSON.stringify(context)}`); context.log(`Request: ${JSON.stringify(request)}`); } @@ -66,6 +72,12 @@ function toRequest(context) { // this header contains the URL the user requested const originalUrl = headers['x-ms-original-url']; + // SWA strips content-type headers from empty POST requests, but SK form actions require the header + // https://github.com/geoffrich/svelte-adapter-azure-swa/issues/178 + if (method === 'POST' && !body && !headers['content-type']) { + headers['content-type'] = 'application/x-www-form-urlencoded'; + } + /** @type {RequestInit} */ const init = { method,