use of com.linecorp.armeria.common.RequestHeadersBuilder in project curiostack by curioswitch.
the class ArmeriaSdkHttpClient method execute.
@Override
public CompletableFuture<Void> execute(AsyncExecuteRequest executeRequest) {
SdkHttpRequest httpRequest = executeRequest.request();
SdkAsyncHttpResponseHandler handler = executeRequest.responseHandler();
RequestHeadersBuilder headersBuilder = RequestHeaders.builder(convert(httpRequest.method()), httpRequest.getUri().toString());
executeRequest.requestContentPublisher().contentLength().ifPresent(contentLength -> headersBuilder.add(HttpHeaderNames.CONTENT_LENGTH, contentLength.toString()));
for (Map.Entry<String, List<String>> header : httpRequest.headers().entrySet()) {
headersBuilder.add(header.getKey(), header.getValue());
}
Publisher<HttpData> requestStream = delegate -> executeRequest.requestContentPublisher().subscribe(new SdkToHttpDataSubscriber(delegate));
HttpRequest request = HttpRequest.of(headersBuilder.build(), requestStream);
HttpResponse response = client.execute(request);
response.subscribe(new ResponseSubscriber(handler));
CompletableFuture<Void> completionFuture = response.whenComplete();
completionFuture.whenComplete((unused, t) -> {
if (t != null) {
// Subscriber.onError, SdkAsyncHttpResponseHandler.onError, the returned future, and any
// thrown exception are all ways of communicating errors to the SDK. This seems like two
// too many but cover all the bases just in case.
handler.onError(t);
}
});
return completionFuture;
}
Aggregations