@@ -235,9 +235,8 @@ public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IO
235
235
context = HttpClientContext .create ();
236
236
}
237
237
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 )) {
241
240
RequestConfig config = null ;
242
241
// Use request configuration given by the user, when available
243
242
if (httpRequest instanceof Configurable configurable ) {
@@ -256,6 +255,18 @@ public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IO
256
255
return new HttpComponentsClientHttpRequest (client , httpRequest , context );
257
256
}
258
257
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
+
259
270
260
271
/**
261
272
* Create a default {@link RequestConfig} to use with the given client.
0 commit comments