diff --git a/src/main/java/com/google/devtools/build/lib/remote/http/HttpDownloadHandler.java b/src/main/java/com/google/devtools/build/lib/remote/http/HttpDownloadHandler.java index 35bea78d11ca37..89e78e11df2730 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/http/HttpDownloadHandler.java +++ b/src/main/java/com/google/devtools/build/lib/remote/http/HttpDownloadHandler.java @@ -47,8 +47,6 @@ final class HttpDownloadHandler extends AbstractHttpHandler { private String path; /** the offset at which to download */ private long offset; - /** the bytes to skip in a full or chunked response */ - private OptionalInt skipBytes; public HttpDownloadHandler( Credentials credentials, ImmutableList> extraHttpHeaders) { @@ -91,14 +89,6 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Ex if (contentLengthSet) { contentLength = HttpUtil.getContentLength(response); } - if (offset != 0) { - // We are in a retried download and received a full response. - // We need to skip `offset` bytes of the response to continue writing from the offset. - if (!skipBytes.isPresent()) { - // This is the first chunk, or the full response. - skipBytes = OptionalInt.of((int)offset); - } - } downloadSucceeded = response.status().equals(HttpResponseStatus.OK); if (!downloadSucceeded) { out = new ByteArrayOutputStream(); @@ -111,13 +101,13 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Ex ByteBuf content = ((HttpContent) msg).content(); int readableBytes = content.readableBytes(); - if (skipBytes.isPresent() && skipBytes.getAsInt() > 0) { - int skipNow = skipBytes.getAsInt(); + if (offset > 0) { + int skipNow = (int)offset; if (skipNow >= readableBytes) { skipNow = readableBytes; } content.readerIndex(content.readerIndex() + skipNow); - skipBytes = OptionalInt.of(skipBytes.getAsInt() - skipNow); + offset -= skipNow; readableBytes = readableBytes - skipNow; } content.readBytes(out, readableBytes); @@ -153,7 +143,6 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) out = cmd.out(); path = constructPath(cmd.uri(), cmd.digest().getHash(), cmd.casDownload()); offset = cmd.offset(); - skipBytes = OptionalInt.empty(); HttpRequest request = buildRequest(path, constructHost(cmd.uri())); addCredentialHeaders(request, cmd.uri()); addExtraRemoteHeaders(request);