@@ -86,17 +86,25 @@ export function runWithContext<T>(context: Context, fn: () => T) {
86
86
return fn ( ) ;
87
87
}
88
88
89
- // `attackDetected`, `consumedRateLimitForIP` and `consumedRateLimitForUser`
90
- // are carried over if there's an existing context
91
- // Only in case of a top level context, we should reset them first
92
- // This is more for tests than for real usage
93
- delete context . cache ;
94
- delete context . attackDetected ;
95
- delete context . consumedRateLimitForIP ;
96
- delete context . consumedRateLimitForUser ;
89
+ // We need to create a new context without `attackDetected`, `consumedRateLimitForIP`, ...
90
+ const topLevelContext : Context = {
91
+ url : context . url ,
92
+ method : context . method ,
93
+ query : context . query ,
94
+ headers : context . headers ,
95
+ routeParams : context . routeParams ,
96
+ remoteAddress : context . remoteAddress ,
97
+ body : context . body ,
98
+ cookies : context . cookies ,
99
+ source : context . source ,
100
+ route : context . route ,
101
+ graphql : context . graphql ,
102
+ xml : context . xml ,
103
+ subdomains : context . subdomains ,
104
+ } ;
97
105
98
106
// If there's no context yet, we create a new context and run the function with it
99
- return ContextStorage . run ( context , fn ) ;
107
+ return ContextStorage . run ( topLevelContext , fn ) ;
100
108
}
101
109
102
110
/**
0 commit comments