Skip to content

Commit c30d2fa

Browse files
committed
TODOs from reviews
1 parent 1abce9d commit c30d2fa

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPart.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ public final Content.Source createContentSource()
354354
@Override
355355
public Content.Source newContentSource(ByteBufferPool.Sized bufferPool, long offset, long length)
356356
{
357+
// TODO support offset and length
357358
return newContentSource();
358359
}
359360

@@ -502,6 +503,7 @@ public ByteBufferPart(String name, String fileName, HttpFields fields, List<Byte
502503
@Override
503504
public Content.Source newContentSource(ByteBufferPool.Sized bufferPool, long offset, long length)
504505
{
506+
// TODO: support offset and length
505507
return new ByteBufferContentSource(content);
506508
}
507509

@@ -538,6 +540,7 @@ public ChunksPart(String name, String fileName, HttpFields fields, List<Content.
538540
@Override
539541
public Content.Source newContentSource(ByteBufferPool.Sized bufferPool, long offset, long length)
540542
{
543+
// TODO support offset and length
541544
try (AutoLock ignored = lock.lock())
542545
{
543546
if (closed)

jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/Content.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ static Content.Source from(ByteBufferPool.Sized byteBufferPool, Path path)
229229
*/
230230
static Content.Source from(ByteBufferPool.Sized byteBufferPool, Path path, long offset, long length)
231231
{
232+
// TODO define contract for offset/lengths outside of bounds
232233
return new ByteChannelContentSource.PathContentSource(byteBufferPool, path, offset, length);
233234
}
234235

@@ -253,6 +254,7 @@ static Content.Source from(ByteBufferPool.Sized byteBufferPool, ByteChannel byte
253254
*/
254255
static Content.Source from(ByteBufferPool.Sized byteBufferPool, SeekableByteChannel seekableByteChannel, long offset, long length)
255256
{
257+
// TODO define contract for offset/lengths outside of bounds
256258
return new ByteChannelContentSource(byteBufferPool, seekableByteChannel, offset, length);
257259
}
258260

@@ -282,6 +284,7 @@ static Content.Source from(ByteBufferPool.Sized byteBufferPool, InputStream inpu
282284
*/
283285
static Content.Source from(ByteBufferPool.Sized byteBufferPool, InputStream inputStream, long offset, long length)
284286
{
287+
// TODO define contract for offset/lengths outside of bounds
285288
return new InputStreamContentSource(inputStream, byteBufferPool, offset, length);
286289
}
287290

jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/internal/ByteChannelContentSource.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ public ByteChannelContentSource(SeekableByteChannel seekableByteChannel, long of
5656

5757
public ByteChannelContentSource(ByteBufferPool.Sized byteBufferPool, SeekableByteChannel seekableByteChannel, long offset, long length)
5858
{
59+
// TODO define contract for offset/lengths outside of bounds
5960
this(byteBufferPool, (ByteChannel)seekableByteChannel, offset, length);
6061
if (offset >= 0 && seekableByteChannel != null)
6162
{
6263
try
6364
{
65+
// TODO negative offset is an IAE, but a too large offset is corrected, but length is not checked.
6466
seekableByteChannel.position(offset);
6567
}
6668
catch (IOException e)
@@ -83,6 +85,7 @@ public ByteChannelContentSource(ByteBufferPool.Sized byteBufferPool, ByteChannel
8385

8486
private ByteChannelContentSource(ByteBufferPool.Sized byteBufferPool, ByteChannel byteChannel, long offset, long length)
8587
{
88+
// TODO Is this the contract we want for offset/length? We are correcting negative offset, but not checking actual size.
8689
_byteBufferPool = Objects.requireNonNullElse(byteBufferPool, ByteBufferPool.SIZED_NON_POOLING);
8790
_byteChannel = byteChannel;
8891
_offset = offset < 0 ? 0 : offset;
@@ -270,7 +273,15 @@ public PathContentSource(ByteBufferPool.Sized byteBufferPool, Path path)
270273

271274
public PathContentSource(ByteBufferPool.Sized byteBufferPool, Path path, long offset, long length)
272275
{
273-
super(byteBufferPool, null, offset, length < 0L ? size(path) : length);
276+
this (byteBufferPool, path, size(path), offset, length);
277+
}
278+
279+
private PathContentSource(ByteBufferPool.Sized byteBufferPool, Path path, long size, long offset, long length)
280+
{
281+
// TODO Is this the contract we want for offset/length? auto correcting it? Validity can be checked in super.
282+
super(byteBufferPool, null,
283+
Math.min(offset, size),
284+
Math.min(length, size - offset));
274285
_path = path;
275286
}
276287

jetty-core/jetty-io/src/test/java/org/eclipse/jetty/io/IOResourcesTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void testAsContentSource(Resource resource) throws Exception
180180

181181
@ParameterizedTest
182182
@MethodSource("all")
183-
public void testAsContentSourceWithFirst(Resource resource) throws Exception
183+
public void testAsContentSourceWithOffset(Resource resource) throws Exception
184184
{
185185
TestSink sink = new TestSink();
186186
Callback.Completable callback = new Callback.Completable();
@@ -211,7 +211,7 @@ public void testAsContentSourceWithLength(Resource resource) throws Exception
211211

212212
@ParameterizedTest
213213
@MethodSource("all")
214-
public void testAsContentSourceWithFirstAndLength(Resource resource) throws Exception
214+
public void testAsContentSourceWithOffsetAndLength(Resource resource) throws Exception
215215
{
216216
TestSink sink = new TestSink();
217217
Callback.Completable callback = new Callback.Completable();
@@ -243,7 +243,7 @@ public void testCopy(Resource resource) throws Exception
243243

244244
@ParameterizedTest
245245
@MethodSource("all")
246-
public void testCopyWithFirst(Resource resource) throws Exception
246+
public void testCopyWithOffset(Resource resource) throws Exception
247247
{
248248
TestSink sink = new TestSink();
249249
Callback.Completable callback = new Callback.Completable();
@@ -273,7 +273,7 @@ public void testCopyWithLength(Resource resource) throws Exception
273273

274274
@ParameterizedTest
275275
@MethodSource("all")
276-
public void testCopyWithFirstAndLength(Resource resource) throws Exception
276+
public void testCopyWithOffsetAndLength(Resource resource) throws Exception
277277
{
278278
TestSink sink = new TestSink();
279279
Callback.Completable callback = new Callback.Completable();

0 commit comments

Comments
 (0)