mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-11 22:50:06 +00:00
refactor(core): Simplify webhook request body parsing (no-changelog) (#39031)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user