Copy httpHandlerDecorator in copy constructor for WebHttpHandlerBuilder
This commit also polishes its Javadoc and fixes its test along the way.
This commit is contained in:
committed by
Juergen Hoeller
parent
e34c800467
commit
603d7e93b9
@@ -124,6 +124,7 @@ public final class WebHttpHandlerBuilder {
|
||||
this.codecConfigurer = other.codecConfigurer;
|
||||
this.localeContextResolver = other.localeContextResolver;
|
||||
this.forwardedHeaderTransformer = other.forwardedHeaderTransformer;
|
||||
this.httpHandlerDecorator = other.httpHandlerDecorator;
|
||||
}
|
||||
|
||||
|
||||
@@ -356,7 +357,7 @@ public final class WebHttpHandlerBuilder {
|
||||
* the entire chain and likewise the ability to observe the result of
|
||||
* the entire chain.
|
||||
* @param handlerDecorator the decorator to apply
|
||||
* @since 5.1
|
||||
* @since 5.3
|
||||
*/
|
||||
public WebHttpHandlerBuilder httpHandlerDecorator(Function<HttpHandler, HttpHandler> handlerDecorator) {
|
||||
this.httpHandlerDecorator = (this.httpHandlerDecorator != null ?
|
||||
@@ -365,10 +366,9 @@ public final class WebHttpHandlerBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a {@code ForwardedHeaderTransformer} is configured or not, either
|
||||
* detected from an {@code ApplicationContext} or explicitly configured via
|
||||
* {@link #forwardedHeaderTransformer(ForwardedHeaderTransformer)}.
|
||||
* @since 5.1
|
||||
* Whether a decorator for {@link HttpHandler} is configured or not via
|
||||
* {@link #httpHandlerDecorator(Function)}.
|
||||
* @since 5.3
|
||||
*/
|
||||
public boolean hasHttpHandlerDecorator() {
|
||||
return (this.httpHandlerDecorator != null);
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.web.server.adapter;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -122,15 +123,20 @@ public class WebHttpHandlerBuilderTests {
|
||||
BiFunction<ServerHttpRequest, String, ServerHttpRequest> mutator =
|
||||
(req, value) -> req.mutate().headers(headers -> headers.add("My-Header", value)).build();
|
||||
|
||||
WebHttpHandlerBuilder
|
||||
AtomicBoolean success = new AtomicBoolean(false);
|
||||
HttpHandler httpHandler = WebHttpHandlerBuilder
|
||||
.webHandler(exchange -> {
|
||||
HttpHeaders headers = exchange.getRequest().getHeaders();
|
||||
assertThat(headers.getFirst("My-Header")).isEqualTo("1-2-3");
|
||||
assertThat(headers.get("My-Header")).containsExactlyInAnyOrder("1", "2", "3");
|
||||
success.set(true);
|
||||
return Mono.empty();
|
||||
})
|
||||
.httpHandlerDecorator(handler -> (req, res) -> handler.handle(mutator.apply(req, "1"), res))
|
||||
.httpHandlerDecorator(handler -> (req, res) -> handler.handle(mutator.apply(req, "2"), res))
|
||||
.httpHandlerDecorator(handler -> (req, res) -> handler.handle(mutator.apply(req, "3"), res));
|
||||
.httpHandlerDecorator(handler -> (req, res) -> handler.handle(mutator.apply(req, "3"), res)).build();
|
||||
|
||||
httpHandler.handle(MockServerHttpRequest.get("/").build(), new MockServerHttpResponse()).block();
|
||||
assertThat(success.get()).isTrue();
|
||||
}
|
||||
|
||||
private static Mono<Void> writeToResponse(ServerWebExchange exchange, String value) {
|
||||
|
||||
Reference in New Issue
Block a user