With the move to Spring Framework 6 the read-timeout functionality was removed from HttpComponentsClientHttpRequestFactory. This has the side effect that it was not possible to use one Apache HTTP Client within an application that connects to different targets with different read-timeouts. The workaround mentioned to use Apache HTTP Client ConnectionConfig also only configures the socket timeout. This is the timeout between receiving two packets and not the timeout until a response is received.
The Apache HTTP Client 5 RequestConfig class has an attribute called responseTimeout which has semantically the same meaning to timeout when the response was not received within the set time. My proposal is to bring back the readTimeout attribute in HttpComponentsClientHttpRequestFactory and in the method mergeRequestConfig propagate the readTimout as responseTimeout to Apache HTTP Client's RequestConfig.
Comment From: snicoll
@danielrohe thanks for the suggestion. HttpComponentsClientHttpRequestFactory
provides the hookpoint that you need to merge this attribute yourself so I don't see it as not possible.
I am not an expert in this area but it's not obvious to me that responseTimeout
could be used to configure what used to be called readTimeout
. Looking at the deprecation message, it didn't feel this was considered as an option back then. Perhaps @poutsma remembers and has an opinion on this proposal?
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: poutsma
Since this change was made about 18 months ago, I cannot exactly remember why I deprecated that method. I think it was because the name readTimeout
was a misnomer, and did not properly represent what it actually stood for, i.e. a socket timeout. As to mapping it to the responseTimeout
property: that was never considered, because it would lead to unexpected behavior when users upgrade.
In general, the timeout properties exposed by the request factories, including the HttpComponentsClientHttpRequestFactory
, were introduced in a time when XML configuration was still popular, and are rather limited. These days, using configuration classes and annotated bean methods, you are typically better off customizing the HttpClient
in the exact way you prefer to use it, and provide it to the HttpComponentsClientHttpRequestFactory
.