spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.95k stars 1.29k forks source link

Allow Users To Customize HttpClient #2410

Closed hpoettker closed 5 months ago

hpoettker commented 5 months ago

Problem description

I can use the config server with Bitbucket (v8.19.1) over http and authenticate with a token by exposing a bean like this:

@Bean
public TransportConfigCallback tokenAuthCallback() {
  var headers = Map.of("Authorization", "Bearer " + TOKEN);
  return transport -> {
    if (transport instanceof TransportHttp transportHttp) {
      transportHttp.setAdditionalHeaders(headers);
    }
  };
}

This works generally fine but produces a warning like the following in the config service on every http connection to the repository:

WARN o.a.h.c.protocol.ResponseProcessCookies : Invalid cookie header: "Set-Cookie: BITBUCKETSESSIONID=XXXX; Max-Age=1209600; Expires=Thu, 09 May 2024 13:45:48 GMT; Path=/; Secure; HttpOnly". Invalid 'expires' attribute: Thu, 09 May 2024 13:45:48 GMT

Root cause

The problem can be fixed by setting the cookie spec of the request config to STANDARD with code like this (e.g. in HttpClient4Support):

httpClientBuilder.setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD))

Feature request

Setting the cookie spec of the underlying HttpClient is not impossible but rather elaborate at the moment (e.g. by redefining the implementation of ConfigurableHttpConnectionFactory). It would be great if JGitEnvironmentProperties had a property cookieSpec that would allow to set the cookie spec as needed.

ryanjbaxter commented 5 months ago

Rather than introducing a property to do this I think it would provide us more flexibility if we added a way to customize the HttpClient. PR #2413 should accomplish this.