From 4b87c30f6216bc69d2fb40875d9b1d0da7ab6fbd Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 22 Dec 2023 15:52:38 -0500 Subject: [PATCH] fix: bug where body wasn't properly sent on ap-style content-types --- src/request.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/request.js b/src/request.js index e7621eb0e2..bb1a406ebd 100644 --- a/src/request.js +++ b/src/request.js @@ -13,6 +13,7 @@ async function call(url, method, { body, timeout, jar, ...config } = {}) { fetchImpl = fetchCookie(fetch, jar); } + const jsonTest = /application\/([a-z]+\+)?json/; const opts = { ...config, method, @@ -26,7 +27,7 @@ async function call(url, method, { body, timeout, jar, ...config } = {}) { } if (body && ['POST', 'PUT', 'PATCH', 'DEL', 'DELETE'].includes(method)) { - if (opts.headers['content-type'] && opts.headers['content-type'].startsWith('application/json')) { + if (opts.headers['content-type'] && jsonTest.test(opts.headers['content-type'])) { opts.body = JSON.stringify(body); } else { opts.body = body; @@ -37,7 +38,6 @@ async function call(url, method, { body, timeout, jar, ...config } = {}) { const { headers } = response; const contentType = headers.get('content-type'); - const jsonTest = /application\/([a-z]+\+)?json/; const isJSON = contentType && jsonTest.test(contentType); let respBody = await response.text(); if (isJSON && respBody) {