refactor(core): Simplify webhook request body parsing (no-changelog) (#39031)

This commit is contained in:
Tomi Turtiainen
2026-09-18 07:47:34 +00:00
committed by GitHub
parent 296d1ff6c1
commit 24e9125a7e
+16 -14
View File
@@ -1416,6 +1416,18 @@ function requiresMultipartFormData(node: INode): boolean {
);
}
function isParsableContentType(contentType: string | undefined): boolean {
if (!contentType) return false;
return (
contentType.startsWith('application/json') ||
contentType.startsWith('text/plain') ||
contentType.startsWith('application/x-www-form-urlencoded') ||
contentType.endsWith('/xml') ||
contentType.endsWith('+xml')
);
}
/**
* Parses the request body (form, xml, json, form-urlencoded, etc.) if needed
* into the `req.body` property.
@@ -1453,22 +1465,12 @@ async function parseRequestBody(
const { body, cleanup } = await parseFormData(req);
req.body = body;
return cleanup;
} else {
if (nodeVersion > 1) {
if (
contentType?.startsWith('application/json') ||
contentType?.startsWith('text/plain') ||
contentType?.startsWith('application/x-www-form-urlencoded') ||
contentType?.endsWith('/xml') ||
contentType?.endsWith('+xml')
) {
await parseBody(req);
}
} else {
await parseBody(req);
}
}
if (nodeVersion > 1 && !isParsableContentType(contentType)) return undefined;
await parseBody(req);
return undefined;
}