Browse Source

Add ExchangeFilterFunction.ofRequestProcessor and ofResponseProcessor

pull/1223/head
Arjen Poutsma 8 years ago
parent
commit
c96badc794
  1. 28
      spring-web/src/main/java/org/springframework/web/client/reactive/ExchangeFilterFunction.java

28
spring-web/src/main/java/org/springframework/web/client/reactive/ExchangeFilterFunction.java

@ -16,6 +16,8 @@ @@ -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 { @@ -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<ClientRequest<?>,
Mono<ClientRequest<?>>> 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<ClientResponse,
Mono<ClientResponse>> responseProcessor) {
Assert.notNull(responseProcessor, "'responseProcessor' must not be null");
return (request, next) -> next.exchange(request).then(responseProcessor);
}
}

Loading…
Cancel
Save