use of io.netty.channel.ChannelProgressivePromise in project async-http-client by AsyncHttpClient.
the class NettyRequestSender method writeRequest.
public <T> void writeRequest(NettyResponseFuture<T> future, Channel channel) {
NettyRequest nettyRequest = future.getNettyRequest();
HttpRequest httpRequest = nettyRequest.getHttpRequest();
AsyncHandler<T> handler = future.getAsyncHandler();
// we just let it go and the channelInactive do its work
if (!Channels.isChannelValid(channel))
return;
try {
if (handler instanceof TransferCompletionHandler)
configureTransferAdapter(handler, httpRequest);
boolean writeBody = !future.isDontWriteBodyBecauseExpectContinue() && httpRequest.method() != HttpMethod.CONNECT && nettyRequest.getBody() != null;
if (!future.isHeadersAlreadyWrittenOnContinue()) {
if (handler instanceof AsyncHandlerExtensions) {
AsyncHandlerExtensions.class.cast(handler).onRequestSend(nettyRequest);
}
// if the request has a body, we want to track progress
if (writeBody) {
ChannelProgressivePromise promise = channel.newProgressivePromise();
ChannelFuture f = channel.write(httpRequest, promise);
f.addListener(new WriteProgressListener(future, true, 0L));
} else {
// we can just track write completion
ChannelPromise promise = channel.newPromise();
ChannelFuture f = channel.writeAndFlush(httpRequest, promise);
f.addListener(new WriteCompleteListener(future));
}
}
if (writeBody)
nettyRequest.getBody().write(channel, future);
// don't bother scheduling read timeout if channel became invalid
if (Channels.isChannelValid(channel))
scheduleReadTimeout(future);
} catch (Exception e) {
LOGGER.error("Can't write request", e);
abort(channel, future, e);
}
}
Aggregations