From f68e7466fdcc84148f55922109fc626de262c848 Mon Sep 17 00:00:00 2001 From: Samuel Lippert Date: Sat, 13 Jan 2024 12:23:37 -0600 Subject: [PATCH] Default to json content type header --- worker.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/worker.js b/worker.js index 5882ce9..2f5fc9a 100644 --- a/worker.js +++ b/worker.js @@ -65,10 +65,10 @@ export class State { const init = callbacks[i].init || meta?.init || {} init.headers = callbacks[i].headers || meta?.headers || init.headers || {} init.method = callbacks[i].method || meta?.method || init.method || init.body ? 'POST' : 'GET' - if (!init.body && ['POST', 'PUT', 'PATCH'].includes(init.method)) { + if (!init.body && ['POST', 'PUT', 'PATCH'].includes(init.method)) init.body = JSON.stringify(callbacks[i].body || meta?.body || state.event) - if (!init.headers['content-type']) init.headers['content-type'] = 'application/json' - } + if (init.body && !init.headers['content-type']) + init.headers['content-type'] = 'application/json' console.log({ url, init, state }) const data = await fetch(url, init) // Escape special regex characters and replace x with \d to check if the callback status code matches an event (e.g. 2xx)