Field routesToCache inner class AdaptCachedBodyGlobalFilter maybe should be modified
Describe. I noticed that it's a good way to use AdaptCachedBodyGlobalFilter to cache request body in the scenario of reuse.And I see it listening a EnableBodyCachingEvent event to judge whether or not to cache the request body.As a result, the field routesToCache will only have the entries with true value.I also notice the RetryGatewayFilterFactory use the event.Once I configure the routes with retry filter, the route will have the feature with caching request body permanently.I can't stop the behavior by revise the configuration in configuration center which support hot loading by refreshing routes.
private ConcurrentMap<String, Boolean> routesToCache = new ConcurrentHashMap<>();
@Override
public void onApplicationEvent(EnableBodyCachingEvent event) {
this.routesToCache.putIfAbsent(event.getRouteId(), true);
}
Describe the solution you'd like I think AdaptCachedBodyGlobalFilter should support one more event such as DisableBodyCachingEvent to set/delete the entry in routesToCache.
+1 for DisableBodyCachingEvent.
In our scenario, routes can have a metadata flag that enables or disables caching for that specific route. So if the route is added via the actuator API with enabled: true and then updated with enabled: false there is no way to update routesToCache.
hi, @ryanjbaxter,I have submitted a fix in #3406.
The change introduces a marker interface to identify filters that require request body caching. AdaptCachedBodyGlobalFilter now checks the active route filters, preventing stale Retry registrations from keeping body caching enabled after route updates.
Existing event-based registration is retained for compatibility with other filters.
Added regression tests and verified the Retry integration tests. All 22 tests pass.
@yashdotdev13 I do not think #3406 is robust enough. It does not account for other filters that might need to retry, the instance check will fail when the filter is wrapped, and it does not deal with the stale filter problem