Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpComponentsClientHttpRequestFactory setReadTimeout not working with httpclient 5.4 #33806

Closed
tvahrst opened this issue Oct 28, 2024 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@tvahrst
Copy link

tvahrst commented Oct 28, 2024

httpcomponents httpclient5 changed the internal implementation of HttpClientContext with version 5.4

apache/httpcomponents-client@762b18f
using instance variables for standard attributes instead of map-like attributes.

With this change, the current implementationof HttpComponentClientHttpRequestFactory#createRequest does not work (anymore), because it uses the old context.getAttribute() and context.setAttribute() Methods which do not have any effect anymore (at least on HttpClientContext instances)

	public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
        ...
		// Request configuration not set in the context
		if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {

        ....
			if (config != null) {
				context.setAttribute(HttpClientContext.REQUEST_CONFIG, config);
			}
		}
		return new HttpComponentsClientHttpRequest(client, httpRequest, context);
	}

As an side effect, the new support for readtimeout isnt working for RestTemplates und RestClients

A solution might be to use the getter/setter Methods for RequestConfig:

		HttpClientContext httpClientContext = HttpClientContext.cast(context);

		// Request configuration not set in the context
		if (httpClientContext.getRequestConfig() == null) {
			// Use request configuration given by the user, when available
			RequestConfig config = null;
			if (httpRequest instanceof Configurable configurable) {
				config = configurable.getConfig();
			}
			if (config == null) {
				config = createRequestConfig(client);
			}
			if (config != null) {
				httpClientContext.setRequestConfig(config);
			}
		}
		return new HttpComponentsClientHttpRequest(client, httpRequest, context);

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 28, 2024
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Oct 28, 2024
@jhoeller jhoeller added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 29, 2024
@jhoeller jhoeller self-assigned this Oct 29, 2024
@jhoeller jhoeller added this to the 6.1.15 milestone Oct 29, 2024
@jhoeller jhoeller changed the title Spring Framework 6.2.0 RC3 HttpComponentsClientHttpRequestFactory setReadTimeout not working with httpclient 5.4 HttpComponentsClientHttpRequestFactory setReadTimeout not working with httpclient 5.4 Oct 29, 2024
@jhoeller
Copy link
Contributor

@tvahrst please give the latest 6.1.15 or 6.2.0 snapshot a try whether it works for you with Apache HttpClient 5.4 now...

@tvahrst
Copy link
Author

tvahrst commented Nov 3, 2024

@jhoeller looks good, readtimeout values are honored by RestTemplates/RestClients

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants