From 0ef50d62ccaa70ea09b693519ddb80d73530b38f Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Wed, 24 Jul 2024 21:10:56 +0100 Subject: [PATCH] fix: make a more sensible decision about matching body ignore bodies sent in HEAD, GET and DELETE --- packages/core/src/Matchers.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/core/src/Matchers.js b/packages/core/src/Matchers.js index 665a7bdd..b4bff45d 100644 --- a/packages/core/src/Matchers.js +++ b/packages/core/src/Matchers.js @@ -177,10 +177,16 @@ const getExpressParamsMatcher = ({ params: expectedParams, url }) => { const getBodyMatcher = (route) => { const { body: expectedBody } = route; + if (!expectedBody) { + return; + } + return ({ options: { body, method = 'get' } }) => { - if (method.toLowerCase() === 'get') { - // GET requests don’t send a body so the body matcher should be ignored for them - return true; + if (['get', 'head', 'delete'].includes(method.toLowerCase())) { + // GET requests don’t send a body so even if it exists in the options + // we treat as no body because it would never actually make it to the server + // in the application code + return false; } let sentBody;