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

Simplify use of HttpContext in HttpComponentsClientHttpRequestFactory in support of user associated connections #25066

Closed
rstoyanchev opened this issue May 13, 2020 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@rstoyanchev
Copy link
Contributor

rstoyanchev commented May 13, 2020

As described in the Apache HttpClient docs a pooled connection may be associated with a user, for example if there is a client certificate involved such as with mutual TLS. In that case it becomes necessary to select a user token for each request to ensure only pooled connections for that user may be re-used.

There is a UserTokenHandler strategy in Apache HttpComponents but in the 4.5.x branch that is only used to associate an already established connection with the local user. So that strategy alone can't be used as a solution (e.g. to use a fixed single identity) and applications have to set the user token on the ClientContext before each request. Currently the only way to do that with the RestTemplate is by overriding HttpComponentsClientHttpRequestFactory#createHttpContext.

All this is not easy to find, here are some example SO threads [1] and [2] and even then having to override a protected method along with lack of any guidance feels less than ideal.

We can't remove the need for an application to decide which request is associated with which user but we can make this a little easier and better supported by allowing a fixed user token to be configured on HttpComponentsClientHttpRequestFactory or accepting a BiFunction to create the HttpContext for each request that would at least eliminate the need to extend. We can also improve the Javadoc to provide concrete pointers for those cases.

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels May 13, 2020
@rstoyanchev rstoyanchev added this to the 5.2.7 milestone May 13, 2020
@rstoyanchev rstoyanchev self-assigned this May 13, 2020
@rstoyanchev rstoyanchev changed the title Simplify use of HttpContext in HttpComponentsClientHttpRequestFactory Simplify use of HttpContext in HttpComponentsClientHttpRequestFactory in support of user associated connections May 13, 2020
FelixFly pushed a commit to FelixFly/spring-framework that referenced this issue Aug 16, 2020
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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant