Remove applyAttributes flag from contribution
See gh-29958
This commit is contained in:
@@ -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<String, Object> attributes;
|
||||
|
||||
private final boolean applyAttributes;
|
||||
|
||||
private final AtomicReference<State> state = new AtomicReference<>(State.NEW);
|
||||
|
||||
private final List<Supplier<? extends Publisher<Void>>> 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() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,14 +48,4 @@ public interface ClientHttpConnector {
|
||||
Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
|
||||
Function<? super ClientHttpRequest, Mono<Void>> 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();
|
||||
|
||||
}
|
||||
|
||||
@@ -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<ClientHttpResponse> execute(HttpComponentsClientHttpRequest request, HttpClientContext context) {
|
||||
AsyncRequestProducer requestProducer = request.toRequestProducer();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -96,7 +96,7 @@ public class JdkClientHttpConnector implements ClientHttpConnector {
|
||||
public Mono<ClientHttpResponse> connect(
|
||||
HttpMethod method, URI uri, Function<? super ClientHttpRequest, Mono<Void>> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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<Void> writeWith(Publisher<? extends DataBuffer> body) {
|
||||
return doCommit(() -> {
|
||||
|
||||
@@ -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<ClientHttpResponse> execute(JettyClientHttpRequest request) {
|
||||
return Mono.fromDirect(request.toReactiveRequest()
|
||||
.response((reactiveResponse, chunkPublisher) -> {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user