Short circuit caching request body if already done.
Fixes gh-2969
This commit is contained in:
@@ -361,6 +361,14 @@ public final class ServerWebExchangeUtils {
|
||||
*/
|
||||
private static <T> Mono<T> cacheRequestBody(ServerWebExchange exchange, boolean cacheDecoratedRequest,
|
||||
Function<ServerHttpRequest, Mono<T>> function) {
|
||||
// don't cache if body is already cached
|
||||
Object cachedDataBuffer = exchange.getAttribute(CACHED_REQUEST_BODY_ATTR);
|
||||
if (cachedDataBuffer instanceof DataBuffer) {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("body already in exchange attribute, short circuiting");
|
||||
}
|
||||
return Mono.just(exchange.getRequest()).flatMap(function);
|
||||
}
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
DataBufferFactory factory = response.bufferFactory();
|
||||
// Join all the DataBuffers so we have a single DataBuffer for the body
|
||||
|
||||
Reference in New Issue
Block a user