Skip to content

Introduce request attributes in RestClient #32027

Closed
@evkaky

Description

@evkaky

Hi there!
When spring boot 3.2 came out, I considered switching from WebClient to RestClient as the first one needs all interceptors to be written in reactive style which makes them harder to support and understand.
It turns out RestClient doesn't provide any alternates to 2 pretty important features which are present in WebClient and which we heavily use.

  1. no attribute(key, value) method for RestClient. That means it's not possible to pass a value from the call site into the interceptor code. Dozen of auth interceptors become impossible to implement with RestClient. Here is how we use them with WebClient:
myWebClient
    .get()
    .uri("/smth")
    .attribute("token" token)
    .retrieve()
    // ...

// the interceptor code
public ExchangeFilterFunction authenticate() {
    return (request, next) -> {
        String token = request.attribute("token").get().toString();
        // ...
    };
}
  1. No single option to configure timeouts. With WebClient there are lots of them. An example
@Bean
WebClientCustomizer webClientGlobalTimeoutCustomizer() {
    return (WebClient.Builder webClientBuilder) -> {
        ConnectionProvider provider = ConnectionProvider.builder("common")
            .maxIdleTime(Duration.ofSeconds(10))
            .maxLifeTime(Duration.ofSeconds(60))
            .pendingAcquireTimeout(Duration.ofSeconds(30))
            .evictInBackground(Duration.ofSeconds(60))
            .build();

        HttpClient httpClient = HttpClient
            .create(provider)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeoutInMillis)
            .doOnConnected(conn -> conn
                .addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS))
                .addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS)));

        webClientBuilder.clientConnector(new ReactorClientHttpConnector(httpClient));
    };
}

Are those things something which is planned to be implemented in spring boot 3.3+ ? Or there some fundamental issues with RestClient underlying implementation so no attribute() and no timeouts?

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions