diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java index 74b2bb5183..61a5e47f5a 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java @@ -94,8 +94,6 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { @Nullable private MultiValueMap defaultCookies; - private boolean applyAttributes; - @Nullable private List filters; @@ -157,7 +155,6 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { } this.defaultCookies = (other.defaultCookies != null ? new LinkedMultiValueMap<>(other.defaultCookies) : null); - this.applyAttributes = other.applyAttributes; this.filters = (other.filters != null ? new ArrayList<>(other.filters) : null); this.entityResultConsumer = other.entityResultConsumer; this.strategies = other.strategies; @@ -216,12 +213,6 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { return this.defaultCookies; } - @Override - public WebTestClient.Builder applyAttributes(boolean applyAttributes) { - this.applyAttributes = applyAttributes; - return this; - } - @Override public WebTestClient.Builder filter(ExchangeFilterFunction filter) { Assert.notNull(filter, "ExchangeFilterFunction is required"); @@ -321,25 +312,22 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { this.entityResultConsumer, this.responseTimeout, new DefaultWebTestClientBuilder(this)); } - private ClientHttpConnector initConnector() { - final ClientHttpConnector connector; + private static ClientHttpConnector initConnector() { if (reactorNettyClientPresent) { - connector = new ReactorClientHttpConnector(); + return new ReactorClientHttpConnector(); } else if (reactorNetty2ClientPresent) { return new ReactorNetty2ClientHttpConnector(); } else if (jettyClientPresent) { - connector = new JettyClientHttpConnector(); + return new JettyClientHttpConnector(); } else if (httpComponentsClientPresent) { - connector = new HttpComponentsClientHttpConnector(); + return new HttpComponentsClientHttpConnector(); } else { - connector = new JdkClientHttpConnector(); + return new JdkClientHttpConnector(); } - connector.setApplyAttributes(this.applyAttributes); - return connector; } private ExchangeStrategies initExchangeStrategies() { diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/HttpHandlerConnector.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/HttpHandlerConnector.java index 06a44d3d89..f0cfd1ef69 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/HttpHandlerConnector.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/HttpHandlerConnector.java @@ -64,8 +64,6 @@ public class HttpHandlerConnector implements ClientHttpConnector { private final HttpHandler handler; - private boolean applyAttributes = true; - /** * Constructor with the {@link HttpHandler} to handle requests with. @@ -84,16 +82,6 @@ public class HttpHandlerConnector implements ClientHttpConnector { .subscribeOn(Schedulers.parallel()); } - @Override - public void setApplyAttributes(boolean applyAttributes) { - this.applyAttributes = applyAttributes; - } - - @Override - public boolean getApplyAttributes() { - return this.applyAttributes; - } - private Mono doConnect( HttpMethod httpMethod, URI uri, Function> requestCallback) { diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java index f8a14f06c1..96938ac7b7 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java @@ -425,13 +425,6 @@ public interface WebTestClient { */ Builder defaultCookies(Consumer> cookiesConsumer); - /** - * Global option to specify whether or not attributes should be applied to every request, - * if the used {@link ClientHttpConnector} allows it. - * @param applyAttributes whether or not to apply attributes - */ - Builder applyAttributes(boolean applyAttributes); - /** * Add the given filter to the filter chain. * @param filter the filter to be added to the chain diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java index b9124c52f2..1c5d91caea 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java @@ -55,8 +55,6 @@ class WiretapConnector implements ClientHttpConnector { private final Map exchanges = new ConcurrentHashMap<>(); - private boolean applyAttributes = true; - WiretapConnector(ClientHttpConnector delegate) { this.delegate = delegate; @@ -86,16 +84,6 @@ class WiretapConnector implements ClientHttpConnector { }); } - @Override - public void setApplyAttributes(boolean applyAttributes) { - this.applyAttributes = applyAttributes; - } - - @Override - public boolean getApplyAttributes() { - return this.applyAttributes; - } - /** * Create the {@link ExchangeResult} for the given "request-id" header value. */ diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java b/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java index 1628803d60..36a49b58c2 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java @@ -86,8 +86,6 @@ public class MockMvcHttpConnector implements ClientHttpConnector { private final List requestPostProcessors; - private boolean applyAttributes = true; - public MockMvcHttpConnector(MockMvc mockMvc) { this(mockMvc, Collections.emptyList()); @@ -117,16 +115,6 @@ public class MockMvcHttpConnector implements ClientHttpConnector { } } - @Override - public void setApplyAttributes(boolean applyAttributes) { - this.applyAttributes = applyAttributes; - } - - @Override - public boolean getApplyAttributes() { - return this.applyAttributes; - } - private RequestBuilder adaptRequest( HttpMethod httpMethod, URI uri, Function> requestCallback) { diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/WiretapConnectorTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/WiretapConnectorTests.java index c1ed8bd96f..01f6828946 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/WiretapConnectorTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/WiretapConnectorTests.java @@ -18,7 +18,6 @@ package org.springframework.test.web.reactive.server; import java.net.URI; import java.time.Duration; -import java.util.function.Function; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -49,22 +48,7 @@ public class WiretapConnectorTests { public void captureAndClaim() { ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, "/test"); ClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK); - ClientHttpConnector connector = new ClientHttpConnector() { - @Override - public Mono connect(HttpMethod method, URI uri, Function> requestCallback) { - return requestCallback.apply(request).then(Mono.just(response)); - } - - @Override - public void setApplyAttributes(boolean applyAttributes) { - - } - - @Override - public boolean getApplyAttributes() { - return false; - } - }; + ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(Mono.just(response)); ClientRequest clientRequest = ClientRequest.create(HttpMethod.GET, URI.create("/test")) .header(WebTestClient.WEBTESTCLIENT_REQUEST_ID, "1").build(); diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java index 147885bb60..63db636c0a 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,8 +60,6 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest { private final Map attributes; - private final boolean applyAttributes; - private final AtomicReference state = new AtomicReference<>(State.NEW); private final List>> commitActions = new ArrayList<>(4); @@ -71,19 +69,14 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest { public AbstractClientHttpRequest() { - this(new HttpHeaders(), false); + this(new HttpHeaders()); } - public AbstractClientHttpRequest(boolean applyAttributes) { - this(new HttpHeaders(), applyAttributes); - } - - public AbstractClientHttpRequest(HttpHeaders headers, boolean applyAttributes) { + public AbstractClientHttpRequest(HttpHeaders headers) { Assert.notNull(headers, "HttpHeaders must not be null"); this.headers = headers; this.cookies = new LinkedMultiValueMap<>(); this.attributes = new LinkedHashMap<>(); - this.applyAttributes = applyAttributes; } @@ -161,9 +154,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest { Mono.fromRunnable(() -> { applyHeaders(); applyCookies(); - if (this.applyAttributes) { - applyAttributes(); - } + applyAttributes(); this.state.set(State.COMMITTED); })); @@ -193,9 +184,11 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest { protected abstract void applyCookies(); /** - * Add additional attributes from {@link #getAttributes()} to the underlying request. + * Add attributes from {@link #getAttributes()} to the underlying request. * This method is called once only. + * @since 6.2 */ - protected abstract void applyAttributes(); + protected void applyAttributes() { + } } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java index d0cf568670..8de59c9c26 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ClientHttpConnector.java @@ -48,14 +48,4 @@ public interface ClientHttpConnector { Mono connect(HttpMethod method, URI uri, Function> requestCallback); - /** - * Set whether or not attributes should be applied to the underlying http-client library request. - */ - void setApplyAttributes(boolean applyAttributes); - - /** - * Whether or not attributes should be applied to the underlying http-client library request. - */ - boolean getApplyAttributes(); - } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java index 2e5b08fd47..6e445868c2 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java @@ -59,7 +59,6 @@ public class HttpComponentsClientHttpConnector implements ClientHttpConnector, C private DataBufferFactory dataBufferFactory = DefaultDataBufferFactory.sharedInstance; - private boolean applyAttributes = true; /** * Default constructor that creates and starts a new instance of {@link CloseableHttpAsyncClient}. @@ -68,7 +67,6 @@ public class HttpComponentsClientHttpConnector implements ClientHttpConnector, C this(HttpAsyncClients.createDefault()); } - /** * Constructor with a pre-configured {@link CloseableHttpAsyncClient} instance. * @param client the client to use @@ -113,22 +111,11 @@ public class HttpComponentsClientHttpConnector implements ClientHttpConnector, C context.setCookieStore(new BasicCookieStore()); } - HttpComponentsClientHttpRequest request = new HttpComponentsClientHttpRequest( - method, uri, context, this.dataBufferFactory, this.applyAttributes); - + HttpComponentsClientHttpRequest request = + new HttpComponentsClientHttpRequest(method, uri, context, this.dataBufferFactory); return requestCallback.apply(request).then(Mono.defer(() -> execute(request, context))); } - @Override - public void setApplyAttributes(boolean applyAttributes) { - this.applyAttributes = applyAttributes; - } - - @Override - public boolean getApplyAttributes() { - return this.applyAttributes; - } - private Mono execute(HttpComponentsClientHttpRequest request, HttpClientContext context) { AsyncRequestProducer requestProducer = request.toRequestProducer(); diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java index 31659fa7bb..cd95213ca0 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,8 +66,8 @@ class HttpComponentsClientHttpRequest extends AbstractClientHttpRequest { public HttpComponentsClientHttpRequest(HttpMethod method, URI uri, HttpClientContext context, - DataBufferFactory dataBufferFactory, boolean applyAttributes) { - super(applyAttributes); + DataBufferFactory dataBufferFactory) { + this.context = context; this.httpRequest = new BasicHttpRequest(method.name(), uri); this.dataBufferFactory = dataBufferFactory; diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpConnector.java index 33d3b21cfc..4313c65807 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpConnector.java @@ -96,7 +96,7 @@ public class JdkClientHttpConnector implements ClientHttpConnector { public Mono connect( HttpMethod method, URI uri, Function> requestCallback) { - JdkClientHttpRequest jdkClientHttpRequest = new JdkClientHttpRequest(method, uri, this.bufferFactory, getApplyAttributes()); + JdkClientHttpRequest jdkClientHttpRequest = new JdkClientHttpRequest(method, uri, this.bufferFactory); return requestCallback.apply(jdkClientHttpRequest).then(Mono.defer(() -> { HttpRequest httpRequest = jdkClientHttpRequest.getNativeRequest(); @@ -109,19 +109,4 @@ public class JdkClientHttpConnector implements ClientHttpConnector { })); } - /** - * Sets nothing, since {@link JdkClientHttpConnector} does not offer any possibility to add attributes. - */ - @Override - public void setApplyAttributes(boolean applyAttributes) { - } - - /** - * Returns false, since {@link JdkClientHttpConnector} does not offer any possibility to add attributes. - */ - @Override - public boolean getApplyAttributes() { - return false; - } - } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpRequest.java index 28a6ebdc34..faf65dc9ed 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpRequest.java @@ -56,8 +56,7 @@ class JdkClientHttpRequest extends AbstractClientHttpRequest { private final HttpRequest.Builder builder; - public JdkClientHttpRequest(HttpMethod httpMethod, URI uri, DataBufferFactory bufferFactory, boolean applyAttributes) { - super(applyAttributes); + public JdkClientHttpRequest(HttpMethod httpMethod, URI uri, DataBufferFactory bufferFactory) { Assert.notNull(httpMethod, "HttpMethod is required"); Assert.notNull(uri, "URI is required"); Assert.notNull(bufferFactory, "DataBufferFactory is required"); @@ -113,15 +112,6 @@ class JdkClientHttpRequest extends AbstractClientHttpRequest { .flatMap(List::stream).map(HttpCookie::toString).collect(Collectors.joining(";"))); } - /** - * Not implemented, since {@link HttpRequest} does not offer any possibility to add request attributes. - */ - @Override - protected void applyAttributes() { - // TODO - throw new RuntimeException(String.format("Using attributes is not available for %s", HttpRequest.class.getName())); - } - @Override public Mono writeWith(Publisher body) { return doCommit(() -> { diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java index 4bc77cd120..a2895f6ded 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java @@ -52,8 +52,6 @@ public class JettyClientHttpConnector implements ClientHttpConnector { private DataBufferFactory bufferFactory = DefaultDataBufferFactory.sharedInstance; - private boolean applyAttributes = true; - /** * Default constructor that creates a new instance of {@link HttpClient}. @@ -128,21 +126,11 @@ public class JettyClientHttpConnector implements ClientHttpConnector { } Request jettyRequest = this.httpClient.newRequest(uri).method(method.toString()); - JettyClientHttpRequest request = new JettyClientHttpRequest(jettyRequest, this.bufferFactory, getApplyAttributes()); + JettyClientHttpRequest request = new JettyClientHttpRequest(jettyRequest, this.bufferFactory); return requestCallback.apply(request).then(execute(request)); } - @Override - public void setApplyAttributes(boolean applyAttributes) { - this.applyAttributes = applyAttributes; - } - - @Override - public boolean getApplyAttributes() { - return this.applyAttributes; - } - private Mono execute(JettyClientHttpRequest request) { return Mono.fromDirect(request.toReactiveRequest() .response((reactiveResponse, chunkPublisher) -> { diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java index 1538f27ef9..3003651546 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,8 +55,7 @@ class JettyClientHttpRequest extends AbstractClientHttpRequest { private final ReactiveRequest.Builder builder; - public JettyClientHttpRequest(Request jettyRequest, DataBufferFactory bufferFactory, boolean applyAttributes) { - super(applyAttributes); + public JettyClientHttpRequest(Request jettyRequest, DataBufferFactory bufferFactory) { this.jettyRequest = jettyRequest; this.bufferFactory = bufferFactory; this.builder = ReactiveRequest.newBuilder(this.jettyRequest).abortOnCancel(true); diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java index 7e0e6a995e..5f1def633a 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java @@ -66,7 +66,6 @@ public class ReactorClientHttpConnector implements ClientHttpConnector, SmartLif private final Object lifecycleMonitor = new Object(); - private boolean applyAttributes = true; /** * Default constructor. Initializes {@link HttpClient} via: @@ -171,20 +170,10 @@ public class ReactorClientHttpConnector implements ClientHttpConnector, SmartLif return requestSender.uri(uri.toString()); } - @Override - public void setApplyAttributes(boolean applyAttributes) { - this.applyAttributes = applyAttributes; - } - - @Override - public boolean getApplyAttributes() { - return this.applyAttributes; - } - private ReactorClientHttpRequest adaptRequest(HttpMethod method, URI uri, HttpClientRequest request, NettyOutbound nettyOutbound) { - return new ReactorClientHttpRequest(method, uri, request, nettyOutbound, this.applyAttributes); + return new ReactorClientHttpRequest(method, uri, request, nettyOutbound); } @Override diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java index bb3bd255cd..5717637d3c 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpRequest.java @@ -61,8 +61,7 @@ class ReactorClientHttpRequest extends AbstractClientHttpRequest implements Zero private final NettyDataBufferFactory bufferFactory; - public ReactorClientHttpRequest(HttpMethod method, URI uri, HttpClientRequest request, NettyOutbound outbound, boolean applyAttributes) { - super(applyAttributes); + public ReactorClientHttpRequest(HttpMethod method, URI uri, HttpClientRequest request, NettyOutbound outbound) { this.httpMethod = method; this.uri = uri; this.request = request; diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpConnector.java index 3535397cb5..afe14e4f92 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpConnector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,8 +46,6 @@ public class ReactorNetty2ClientHttpConnector implements ClientHttpConnector { private final HttpClient httpClient; - private boolean applyAttributes = true; - /** * Default constructor. Initializes {@link HttpClient} via: @@ -128,20 +126,10 @@ public class ReactorNetty2ClientHttpConnector implements ClientHttpConnector { }); } - @Override - public void setApplyAttributes(boolean applyAttributes) { - this.applyAttributes = applyAttributes; - } - - @Override - public boolean getApplyAttributes() { - return this.applyAttributes; - } - private ReactorNetty2ClientHttpRequest adaptRequest(HttpMethod method, URI uri, HttpClientRequest request, NettyOutbound nettyOutbound) { - return new ReactorNetty2ClientHttpRequest(method, uri, request, nettyOutbound, getApplyAttributes()); + return new ReactorNetty2ClientHttpRequest(method, uri, request, nettyOutbound); } } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpRequest.java index 8ecb1d5a11..8c0a8e685d 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,8 +62,9 @@ class ReactorNetty2ClientHttpRequest extends AbstractClientHttpRequest implement private final Netty5DataBufferFactory bufferFactory; - public ReactorNetty2ClientHttpRequest(HttpMethod method, URI uri, HttpClientRequest request, NettyOutbound outbound, boolean applyAttributes) { - super(applyAttributes); + public ReactorNetty2ClientHttpRequest( + HttpMethod method, URI uri, HttpClientRequest request, NettyOutbound outbound) { + this.httpMethod = method; this.uri = uri; this.request = request; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java index 5fe52d7315..59da4e80d0 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java @@ -89,8 +89,6 @@ final class DefaultWebClientBuilder implements WebClient.Builder { @Nullable private MultiValueMap defaultCookies; - private boolean applyAttributes; - @Nullable private Consumer> defaultRequest; @@ -139,7 +137,6 @@ final class DefaultWebClientBuilder implements WebClient.Builder { this.defaultCookies = (other.defaultCookies != null ? new LinkedMultiValueMap<>(other.defaultCookies) : null); - this.applyAttributes = other.applyAttributes; this.defaultRequest = other.defaultRequest; this.statusHandlers = (other.statusHandlers != null ? new LinkedHashMap<>(other.statusHandlers) : null); this.filters = (other.filters != null ? new ArrayList<>(other.filters) : null); @@ -203,12 +200,6 @@ final class DefaultWebClientBuilder implements WebClient.Builder { return this; } - @Override - public WebClient.Builder applyAttributes(boolean applyAttributes) { - this.applyAttributes = applyAttributes; - return this; - } - private MultiValueMap initCookies() { if (this.defaultCookies == null) { this.defaultCookies = new LinkedMultiValueMap<>(3); @@ -344,24 +335,21 @@ final class DefaultWebClientBuilder implements WebClient.Builder { } private ClientHttpConnector initConnector() { - final ClientHttpConnector connector; if (reactorNettyClientPresent) { - connector = new ReactorClientHttpConnector(); + return new ReactorClientHttpConnector(); } else if (reactorNetty2ClientPresent) { return new ReactorNetty2ClientHttpConnector(); } else if (jettyClientPresent) { - connector = new JettyClientHttpConnector(); + return new JettyClientHttpConnector(); } else if (httpComponentsClientPresent) { - connector = new HttpComponentsClientHttpConnector(); + return new HttpComponentsClientHttpConnector(); } else { - connector = new JdkClientHttpConnector(); + return new JdkClientHttpConnector(); } - connector.setApplyAttributes(this.applyAttributes); - return connector; } private ExchangeStrategies initExchangeStrategies() { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java index 60a25f70f5..02586478e3 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java @@ -250,13 +250,6 @@ public interface WebClient { */ Builder defaultCookies(Consumer> cookiesConsumer); - /** - * Global option to specify whether or not the request attributes should be applied - * to the underlying http-client request, if the used {@link ClientHttpConnector} allows it. - * @param applyAttributes whether or not to apply the attributes - */ - Builder applyAttributes(boolean applyAttributes); - /** * Provide a consumer to customize every request being built. * @param defaultRequest the consumer to use for modifying requests diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java index 39e23da07c..62b1c629fe 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java @@ -192,20 +192,8 @@ class WebClientIntegrationTests { } @ParameterizedWebClientTest - void applyAttributesInNativeRequest(ClientHttpConnector connector) { + void applyAttributesToNativeRequest(ClientHttpConnector connector) { startServer(connector); - connector.setApplyAttributes(true); - checkAttributesInNativeRequest(true); - } - - @ParameterizedWebClientTest - void dontApplyAttributesInNativeRequest(ClientHttpConnector connector) { - startServer(connector); - connector.setApplyAttributes(false); - checkAttributesInNativeRequest(false); - } - - private void checkAttributesInNativeRequest(boolean expectAttributesApplied){ prepareResponse(response -> {}); final AtomicReference nativeRequest = new AtomicReference<>(); @@ -215,36 +203,22 @@ class WebClientIntegrationTests { .httpRequest(clientHttpRequest -> nativeRequest.set(clientHttpRequest.getNativeRequest())) .retrieve() .bodyToMono(Void.class); - StepVerifier.create(result) - .expectComplete() - .verify(); + + StepVerifier.create(result).expectComplete().verify(); + if (nativeRequest.get() instanceof ChannelOperations nativeReq) { Attribute> attributes = nativeReq.channel().attr(AttributeKey.valueOf("attributes")); - if (expectAttributesApplied) { - assertThat(attributes.get()).isNotNull(); - assertThat(attributes.get()).containsEntry("foo", "bar"); - } - else { - assertThat(attributes.get()).isNull(); - } + assertThat(attributes.get()).isNotNull(); + assertThat(attributes.get()).containsEntry("foo", "bar"); } else if (nativeRequest.get() instanceof reactor.netty5.channel.ChannelOperations nativeReq) { - io.netty5.util.Attribute> attributes = nativeReq.channel().attr(io.netty5.util.AttributeKey.valueOf("attributes")); - if (expectAttributesApplied) { - assertThat(attributes.get()).isNotNull(); - assertThat(attributes.get()).containsEntry("foo", "bar"); - } - else { - assertThat(attributes.get()).isNull(); - } + io.netty5.util.Attribute> attributes = + nativeReq.channel().attr(io.netty5.util.AttributeKey.valueOf("attributes")); + assertThat(attributes.get()).isNotNull(); + assertThat(attributes.get()).containsEntry("foo", "bar"); } else if (nativeRequest.get() instanceof Request nativeReq) { - if (expectAttributesApplied) { - assertThat(nativeReq.getAttributes()).containsEntry("foo", "bar"); - } - else { - assertThat(nativeReq.getAttributes()).doesNotContainEntry("foo", "bar"); - } + assertThat(nativeReq.getAttributes()).containsEntry("foo", "bar"); } else if (nativeRequest.get() instanceof org.apache.hc.core5.http.HttpRequest nativeReq) { // TODO get attributes from HttpClientContext