From c96badc794856afa9bd3aec7637b37daa9a95a23 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Thu, 27 Oct 2016 12:59:24 +0200 Subject: [PATCH] Add ExchangeFilterFunction.ofRequestProcessor and ofResponseProcessor --- .../reactive/ExchangeFilterFunction.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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); + } + }