Allow to aggregate a request more than once
Sometimes, users may want to aggregate a request which is already aggregated. For example, in TomcatService or GraphqlService.
In my case, the TomcatService, I want to send a request which is as same as the requested to an upstream. However, it's impossible to access content data (to proxy via WebClient without building another HttpRequest) since the request is aggregated in the TomcatService. Here's an example:
public ResponseEntity<String> doProxy() {
final ServiceRequestContext ctx = ServiceRequestContext.current();
final HttpRequest req = ctx.request();
final HttpRequest duplicatedReq = req.toDuplicator().duplicate();
final AggregatedHttpResponse res = delegate.execute(duplicatedReq).aggregate().join();
return buildResponse(res);
}
It fails because:
subscribed by other subscriber already
Similarly, it would be useful to verify request's signature using content in decorator. The verification is what LINE does in messaging API: Verifying signatures .
My suggestion is to cache aggregated request. First we call req.aggregate(), the req do aggregate. After, whenever we call the req.aggregate(), will return completed CompletableFuture with the aggregated request before. Then the API would be natural.
However, @ikhoon said that there is some edge cases such as SubscriptionOptions. So let's discuss about it.