-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: enhancementA general enhancementA general enhancement
Milestone
Description
As observed in spring-cloud/spring-cloud-sleuth#1199 and workarounded in spring-cloud/spring-cloud-sleuth#1206, some WebClient filters like Sleuth's tracing propagation apply the modifications on the subscription time, but the ClientRequest is passed as a first argument to the filter even before the subscription:
Lines 207 to 211 in 0b9522c
| ExchangeFunction exchange = initExchangeFunction(); | |
| ExchangeFunction filteredExchange = (this.filters != null ? this.filters.stream() | |
| .reduce(ExchangeFilterFunction::andThen) | |
| .map(filter -> filter.apply(exchange)) | |
| .orElse(exchange) : exchange); |
Since some of the filters might be expensive to apply, it makes sense to apply them on subscribe.
Metrics is another subscription-sensitive example.
To keep the ClientRequest argument, one could use Mono.defer to defer the execution of the filter to the subscription time, also to alight with the server-side:
Lines 117 to 123 in d257833
| @Override | |
| public Mono<Void> filter(ServerWebExchange exchange) { | |
| return Mono.defer(() -> | |
| this.currentFilter != null && this.next != null ? | |
| this.currentFilter.filter(exchange, this.next) : | |
| this.handler.handle(exchange)); | |
| } |
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: enhancementA general enhancementA general enhancement