Skip to content

Commit 4a99fa8

Browse files
committed
Merge branch '6.2.x'
2 parents ecdb633 + 6f11711 commit 4a99fa8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,8 @@ public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IO
235235
context = HttpClientContext.create();
236236
}
237237

238-
// Request configuration not set in the context
239-
if (!(context instanceof HttpClientContext clientContext && clientContext.getRequestConfig() != null) &&
240-
context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
238+
// No custom request configuration was set
239+
if (!hasCustomRequestConfig(context)) {
241240
RequestConfig config = null;
242241
// Use request configuration given by the user, when available
243242
if (httpRequest instanceof Configurable configurable) {
@@ -256,6 +255,18 @@ public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IO
256255
return new HttpComponentsClientHttpRequest(client, httpRequest, context);
257256
}
258257

258+
@SuppressWarnings("deprecation") // HttpClientContext.REQUEST_CONFIG
259+
private static boolean hasCustomRequestConfig(HttpContext context) {
260+
if (context instanceof HttpClientContext clientContext) {
261+
// Prior to 5.4, the default config was set to RequestConfig.DEFAULT
262+
// As of 5.4, it is set to null
263+
RequestConfig requestConfig = clientContext.getRequestConfig();
264+
return requestConfig != null && !requestConfig.equals(RequestConfig.DEFAULT);
265+
}
266+
// Prior to 5.4, the config was stored as an attribute
267+
return context.getAttribute(HttpClientContext.REQUEST_CONFIG) != null;
268+
}
269+
259270

260271
/**
261272
* Create a default {@link RequestConfig} to use with the given client.

0 commit comments

Comments
 (0)