Call get/setRequestConfig for HttpClient 5.4 compatibility

Includes upgrade to HttpClient 5.4.1 while retaining a HttpClient 5.1 baseline.

Closes gh-33806
This commit is contained in:
Juergen Hoeller 2024-10-29 23:01:57 +01:00
parent fa21dffcf8
commit 11ebceee38
2 changed files with 9 additions and 5 deletions

View File

@ -101,8 +101,8 @@ dependencies {
api("org.apache.derby:derby:10.16.1.1")
api("org.apache.derby:derbyclient:10.16.1.1")
api("org.apache.derby:derbytools:10.16.1.1")
api("org.apache.httpcomponents.client5:httpclient5:5.4")
api("org.apache.httpcomponents.core5:httpcore5-reactive:5.3")
api("org.apache.httpcomponents.client5:httpclient5:5.4.1")
api("org.apache.httpcomponents.core5:httpcore5-reactive:5.3.1")
api("org.apache.poi:poi-ooxml:5.2.5")
api("org.apache.tomcat.embed:tomcat-embed-core:10.1.28")
api("org.apache.tomcat.embed:tomcat-embed-websocket:10.1.28")

View File

@ -205,7 +205,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
@Override
@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation") // HttpClientContext.REQUEST_CONFIG
public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
HttpClient client = getHttpClient();
@ -217,9 +217,10 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
}
// Request configuration not set in the context
if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
// Use request configuration given by the user, when available
if (!(context instanceof HttpClientContext clientContext && clientContext.getRequestConfig() != null) &&
context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
RequestConfig config = null;
// Use request configuration given by the user, when available
if (httpRequest instanceof Configurable configurable) {
config = configurable.getConfig();
}
@ -227,6 +228,9 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
config = createRequestConfig(client);
}
if (config != null) {
if (context instanceof HttpClientContext clientContext) {
clientContext.setRequestConfig(config);
}
context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
}
}