diff --git a/spring-web/src/main/java/org/springframework/web/client/reactive/ExchangeFilterFunction.java b/spring-web/src/main/java/org/springframework/web/client/reactive/ExchangeFilterFunction.java index 505d78072b..c226cee5b2 100644 --- a/spring-web/src/main/java/org/springframework/web/client/reactive/ExchangeFilterFunction.java +++ b/spring-web/src/main/java/org/springframework/web/client/reactive/ExchangeFilterFunction.java @@ -16,6 +16,8 @@ package org.springframework.web.client.reactive; +import java.util.function.Function; + import reactor.core.publisher.Mono; import org.springframework.util.Assert; @@ -66,4 +68,30 @@ public interface ExchangeFilterFunction { return request -> this.filter(request, exchange); } + /** + * Adapt the given request processor function to a filter function that only operates on the + * {@code ClientRequest}. + * @param requestProcessor the request processor + * @return the filter adaptation of the request processor + */ + static ExchangeFilterFunction ofRequestProcessor(Function, + Mono>> requestProcessor) { + + Assert.notNull(requestProcessor, "'requestProcessor' must not be null"); + return (request, next) -> requestProcessor.apply(request).then(next::exchange); + } + + /** + * Adapt the given response processor function to a filter function that only operates on the + * {@code ClientResponse}. + * @param responseProcessor the response processor + * @return the filter adaptation of the request processor + */ + static ExchangeFilterFunction ofResponseProcessor(Function> responseProcessor) { + + Assert.notNull(responseProcessor, "'responseProcessor' must not be null"); + return (request, next) -> next.exchange(request).then(responseProcessor); + } + }