mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 00:56:13 +01:00
fix: bug where body wasn't properly sent on ap-style content-types
This commit is contained in:
@@ -13,6 +13,7 @@ async function call(url, method, { body, timeout, jar, ...config } = {}) {
|
|||||||
fetchImpl = fetchCookie(fetch, jar);
|
fetchImpl = fetchCookie(fetch, jar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const jsonTest = /application\/([a-z]+\+)?json/;
|
||||||
const opts = {
|
const opts = {
|
||||||
...config,
|
...config,
|
||||||
method,
|
method,
|
||||||
@@ -26,7 +27,7 @@ async function call(url, method, { body, timeout, jar, ...config } = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (body && ['POST', 'PUT', 'PATCH', 'DEL', 'DELETE'].includes(method)) {
|
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);
|
opts.body = JSON.stringify(body);
|
||||||
} else {
|
} else {
|
||||||
opts.body = body;
|
opts.body = body;
|
||||||
@@ -37,7 +38,6 @@ async function call(url, method, { body, timeout, jar, ...config } = {}) {
|
|||||||
|
|
||||||
const { headers } = response;
|
const { headers } = response;
|
||||||
const contentType = headers.get('content-type');
|
const contentType = headers.get('content-type');
|
||||||
const jsonTest = /application\/([a-z]+\+)?json/;
|
|
||||||
const isJSON = contentType && jsonTest.test(contentType);
|
const isJSON = contentType && jsonTest.test(contentType);
|
||||||
let respBody = await response.text();
|
let respBody = await response.text();
|
||||||
if (isJSON && respBody) {
|
if (isJSON && respBody) {
|
||||||
|
|||||||
Reference in New Issue
Block a user