Skip to content

Commit

Permalink
Short circuit caching request body if already done.
Browse files Browse the repository at this point in the history
Fixes gh-2969
  • Loading branch information
spencergibb committed Mar 21, 2024
1 parent c79e9ad commit cc62626
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ public static <T> Mono<T> cacheRequestBody(ServerWebExchange exchange,
*/
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
Expand Down

0 comments on commit cc62626

Please sign in to comment.