Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bc78378
Fix copying of zero length resources
gregw Oct 10, 2025
1abce9d
Fix copying of zero length resources
gregw Oct 10, 2025
c30d2fa
TODOs from reviews
gregw Oct 11, 2025
01d9696
updates from reviews
gregw Oct 11, 2025
a300209
Propose the checkOffsetLengthSize contract
gregw Oct 12, 2025
ce185bf
Propose the checkOffsetLengthSize contract
gregw Oct 12, 2025
e8cd8dd
Propose the checkOffsetLengthSize contract
gregw Oct 13, 2025
4cca316
Propose the checkOffsetLengthSize contract
gregw Oct 13, 2025
7ed9ed7
Propose the checkOffsetLengthSize contract
gregw Oct 13, 2025
ccb80c0
Propose the checkOffsetLengthSize contract
gregw Oct 13, 2025
a61e7f3
More forgiving offsetLengthSize contract
gregw Oct 13, 2025
bab1fdd
Updates from review
gregw Oct 14, 2025
c1d181d
Implementing TODOs; added ContentSourceRange class and improved testing
lachlan-roberts Oct 15, 2025
ae86776
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/jetty-12.…
gregw Oct 15, 2025
4147ef3
PR #13690 - fixes for test failures
lachlan-roberts Oct 15, 2025
1d255e7
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/jetty-12.…
gregw Oct 16, 2025
25a685c
Updates from review
gregw Oct 19, 2025
0706aba
PR #13690 - changes from review
lachlan-roberts Oct 20, 2025
a00d126
PR #13690 - extra test for failure case
lachlan-roberts Oct 20, 2025
c4c6d6a
PR #13690 - changes from review
lachlan-roberts Oct 20, 2025
00856b4
update from review
gregw Oct 24, 2025
8c29420
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/jetty-12.…
gregw Oct 28, 2025
6c725c4
Updates from review
gregw Oct 28, 2025
2fe1d8f
Updates from review
gregw Oct 28, 2025
cc50b37
add missing checks in HttpContent.writeTo() implementations
lorban Oct 28, 2025
e36049c
Updates from review
gregw Oct 28, 2025
8f95ae2
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/jetty-12.…
gregw Oct 28, 2025
a6ca6a7
Updates from review
gregw Oct 28, 2025
ccfc4b9
Updates from review
gregw Oct 28, 2025
9f586b1
Merge branch 'jetty-12.1.x' into fix/jetty-12.1.x/13685-zeroLengthFiles
gregw Oct 29, 2025
b2ebc77
Updates from review
gregw Oct 29, 2025
fc77020
Merge remote-tracking branch 'origin/jetty-12.1.x' into fix/jetty-12.…
gregw Oct 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ public Content.Chunk read()
try (AutoLock ignored = lock.lock())
{
lockedEnsureOpenOrTerminal();

if (_length == 0)
{
lockedSetTerminal(Content.Chunk.EOF);
return Content.Chunk.EOF;
}

if (_terminal != null)
return _terminal;

Expand All @@ -172,7 +179,7 @@ else if (_buffer.isRetained())
{
ByteBuffer byteBuffer = _buffer.getByteBuffer();
BufferUtil.clearToFill(byteBuffer);
if (_length >= 0)
if (_length > 0)
byteBuffer.limit((int)Math.min(_buffer.capacity(), _length - _totalRead));
int read = _byteChannel.read(byteBuffer);
BufferUtil.flipToFlush(byteBuffer, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ public Content.Source newContentSource(ByteBufferPool.Sized bufferPool, long off
public static Stream<Resource> all() throws Exception
{
Path testResourcePath = MavenTestingUtils.getTestResourcePath("keystore.p12");

URI resourceUri = testResourcePath.toUri();
return Stream.of(
ResourceFactory.root().newResource(resourceUri),
ResourceFactory.root().newMemoryResource(resourceUri.toURL()),
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("zero")),
ResourceFactory.root().newResource(MavenTestingUtils.getTestResourcePath("one")),
new URLResourceFactory().newResource(resourceUri),
new TestContentSourceFactoryResource(resourceUri, Files.readAllBytes(testResourcePath))
);
Expand Down Expand Up @@ -181,12 +184,13 @@ public void testAsContentSourceWithFirst(Resource resource) throws Exception
{
TestSink sink = new TestSink();
Callback.Completable callback = new Callback.Completable();

Content.Source contentSource = IOResources.asContentSource(resource, bufferPool, 100, -1);
Content.copy(contentSource, sink, callback);
callback.get();
List<Content.Chunk> chunks = sink.takeAccumulatedChunks();
long sum = chunks.stream().mapToLong(Content.Chunk::remaining).sum();
assertThat(sum, is(resource.length() - 100L));
assertThat(sum, is(Math.max(0L, resource.length() - 100L)));
assertThat(chunks.get(chunks.size() - 1).isLast(), is(true));
}

Expand All @@ -201,7 +205,7 @@ public void testAsContentSourceWithLength(Resource resource) throws Exception
callback.get();
List<Content.Chunk> chunks = sink.takeAccumulatedChunks();
long sum = chunks.stream().mapToLong(Content.Chunk::remaining).sum();
assertThat(sum, is(500L));
assertThat(sum, is(Math.min(resource.length(), 500L)));
assertThat(chunks.get(chunks.size() - 1).isLast(), is(true));
}

Expand All @@ -211,12 +215,15 @@ public void testAsContentSourceWithFirstAndLength(Resource resource) throws Exce
{
TestSink sink = new TestSink();
Callback.Completable callback = new Callback.Completable();
Content.Source contentSource = IOResources.asContentSource(resource, bufferPool, 100, 500);

long offset = Math.min(resource.length(), 100);
long length = Math.min(resource.length() - offset, 500);
Content.Source contentSource = IOResources.asContentSource(resource, bufferPool, offset, length);
Content.copy(contentSource, sink, callback);
callback.get();
List<Content.Chunk> chunks = sink.takeAccumulatedChunks();
long sum = chunks.stream().mapToLong(Content.Chunk::remaining).sum();
assertThat(sum, is(500L));
assertThat(sum, is(length));
assertThat(chunks.get(chunks.size() - 1).isLast(), is(true));
}

Expand All @@ -240,11 +247,12 @@ public void testCopyWithFirst(Resource resource) throws Exception
{
TestSink sink = new TestSink();
Callback.Completable callback = new Callback.Completable();
IOResources.copy(resource, sink, bufferPool, 100, -1, callback);
long offset = Math.min(resource.length(), 100);
IOResources.copy(resource, sink, bufferPool, offset, -1, callback);
callback.get();
List<Content.Chunk> chunks = sink.takeAccumulatedChunks();
long sum = chunks.stream().mapToLong(Content.Chunk::remaining).sum();
assertThat(sum, is(resource.length() - 100L));
assertThat(sum, is(Math.max(0L, resource.length() - 100L)));
assertThat(chunks.get(chunks.size() - 1).isLast(), is(true));
}

Expand All @@ -254,11 +262,12 @@ public void testCopyWithLength(Resource resource) throws Exception
{
TestSink sink = new TestSink();
Callback.Completable callback = new Callback.Completable();
IOResources.copy(resource, sink, bufferPool, 0, 500, callback);
long length = resource.length() >= 0 ? Math.min(resource.length(), 500) : 500;
IOResources.copy(resource, sink, bufferPool, 0, length, callback);
callback.get();
List<Content.Chunk> chunks = sink.takeAccumulatedChunks();
long sum = chunks.stream().mapToLong(Content.Chunk::remaining).sum();
assertThat(sum, is(500L));
assertThat(sum, is(length));
assertThat(chunks.get(chunks.size() - 1).isLast(), is(true));
}

Expand All @@ -268,11 +277,13 @@ public void testCopyWithFirstAndLength(Resource resource) throws Exception
{
TestSink sink = new TestSink();
Callback.Completable callback = new Callback.Completable();
IOResources.copy(resource, sink, bufferPool, 100, 500, callback);
long offset = Math.min(resource.length(), 100);
long length = Math.min(resource.length() - offset, 500);
IOResources.copy(resource, sink, bufferPool, offset, length, callback);
callback.get();
List<Content.Chunk> chunks = sink.takeAccumulatedChunks();
long sum = chunks.stream().mapToLong(Content.Chunk::remaining).sum();
assertThat(sum, is(500L));
assertThat(sum, is(length));
assertThat(chunks.get(chunks.size() - 1).isLast(), is(true));
}

Expand Down
1 change: 1 addition & 0 deletions jetty-core/jetty-io/src/test/resources/one
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
Empty file.