From 8ba4439f8baae52b00027aac9def98daec5d9d32 Mon Sep 17 00:00:00 2001 From: Hans Ott Date: Thu, 25 Jul 2024 14:12:44 +0200 Subject: [PATCH] Only delete cache --- library/agent/Context.ts | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/library/agent/Context.ts b/library/agent/Context.ts index e59dc9f7c..4e09b0a7f 100644 --- a/library/agent/Context.ts +++ b/library/agent/Context.ts @@ -86,25 +86,13 @@ export function runWithContext(context: Context, fn: () => T) { return fn(); } - // We need to create a new context without `attackDetected`, `consumedRateLimitForIP`, ... - const topLevelContext: Context = { - url: context.url, - method: context.method, - query: context.query, - headers: context.headers, - routeParams: context.routeParams, - remoteAddress: context.remoteAddress, - body: context.body, - cookies: context.cookies, - source: context.source, - route: context.route, - graphql: context.graphql, - xml: context.xml, - subdomains: context.subdomains, - }; + // Cleanup lingering cache + // In tests the context is often passed by reference + // Make sure to clean up the cache before running the function + delete context.cache; // If there's no context yet, we create a new context and run the function with it - return ContextStorage.run(topLevelContext, fn); + return ContextStorage.run(context, fn); } /**