armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Allow to aggregate a request more than once

Open 0x1306e6d opened this issue 4 years ago • 0 comments

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.

0x1306e6d avatar Aug 24 '21 10:08 0x1306e6d