From 5c84ad31885ebe4d175e80890665e1f4ef29c7c4 Mon Sep 17 00:00:00 2001 From: dkocher Date: Tue, 20 Oct 2015 09:22:44 +0000 Subject: [PATCH] Fix range header with unknown content length. git-svn-id: https://svn.cyberduck.io/trunk@18373 9e2dff1d-8f06-0410-b5b1-4d70b6340adc --- source/ch/cyberduck/core/s3/S3ReadFeature.java | 4 +-- test/ch/cyberduck/core/s3/S3ReadFeatureTest.java | 37 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/source/ch/cyberduck/core/s3/S3ReadFeature.java b/source/ch/cyberduck/core/s3/S3ReadFeature.java index bd3b1c08e0..134325effc 100644 --- a/source/ch/cyberduck/core/s3/S3ReadFeature.java +++ b/source/ch/cyberduck/core/s3/S3ReadFeature.java @@ -60,7 +60,7 @@ public class S3ReadFeature implements Read { null, // ifMatch null, // ifNoneMatch status.isAppend() ? status.getOffset() : null, - status.isAppend() ? status.getOffset() + status.getLength() : null); + status.isAppend() && status.getLength() > 0 ? status.getOffset() + status.getLength() : null); return object.getDataInputStream(); } else { @@ -72,7 +72,7 @@ public class S3ReadFeature implements Read { null, // ifMatch null, // ifNoneMatch status.isAppend() ? status.getOffset() : null, - status.isAppend() ? status.getOffset() + status.getLength() : null); + status.isAppend() && status.getLength() > 0 ? status.getOffset() + status.getLength() : null); } if(log.isDebugEnabled()) { log.debug(String.format("Reading stream with content length %d", object.getContentLength())); diff --git a/test/ch/cyberduck/core/s3/S3ReadFeatureTest.java b/test/ch/cyberduck/core/s3/S3ReadFeatureTest.java index 5960291d91..c3dbf4f191 100644 --- a/test/ch/cyberduck/core/s3/S3ReadFeatureTest.java +++ b/test/ch/cyberduck/core/s3/S3ReadFeatureTest.java @@ -85,6 +85,43 @@ public class S3ReadFeatureTest extends AbstractTestCase { } @Test + public void testReadRangeUnknownLength() throws Exception { + final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials( + properties.getProperty("s3.key"), properties.getProperty("s3.secret") + )); + final S3Session session = new S3Session(host); + session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener()); + session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); + final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume)); + final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); + new S3TouchFeature(session).touch(test); + final byte[] content = RandomStringUtils.random(1000).getBytes(); + final TransferStatus status = new TransferStatus().length(content.length); + status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content))); + final OutputStream out = new S3WriteFeature(session).write(test, status); + assertNotNull(out); + new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out); + IOUtils.closeQuietly(out); + status.setAppend(true); + status.setOffset(100L); + status.setLength(-1L); + final InputStream in = new S3ReadFeature(session).read(test, status); + assertNotNull(in); + final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length - 100); + new StreamCopier(status, status).transfer(in, buffer); + final byte[] reference = new byte[content.length - 100]; + System.arraycopy(content, 100, reference, 0, content.length - 100); + assertArrayEquals(reference, buffer.toByteArray()); + in.close(); + new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.Callback() { + @Override + public void delete(final Path file) { + } + }); + session.close(); + } + + @Test public void testDownloadGzip() throws Exception { final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials( properties.getProperty("s3.key"), properties.getProperty("s3.secret") -- 2.11.4.GIT