Skip to content

Commit

Permalink
Updates from review.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Dec 12, 2024
1 parent e3cf38f commit 72bb0b1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ private class DecodedContentSource implements Content.Source
private final Content.Source source;
private final Response response;
private long decodedLength;
private boolean last;

private DecodedContentSource(Content.Source source, Response response)
{
Expand Down Expand Up @@ -643,8 +644,11 @@ public Content.Chunk read()

decodedLength += chunk.remaining();

if (chunk.isLast())
if (chunk.isLast() && !last)
{
last = true;
afterDecoding(response, decodedLength);
}

return chunk;
}
Expand Down Expand Up @@ -672,7 +676,13 @@ public void fail(Throwable failure, boolean last)
@Override
public boolean rewind()
{
return source.rewind();
boolean rewound = source.rewind();
if (rewound)
{
decodedLength = 0;
last = false;
}
return rewound;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.io.ArrayByteBufferPool;
import org.eclipse.jetty.io.Content;
import org.eclipse.jetty.io.RetainableByteBuffer;
import org.eclipse.jetty.io.content.ContentSourceTransformer;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.StringUtil;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -63,13 +65,17 @@ protected Content.Chunk transform(Content.Chunk chunk)
if (chunk.isEmpty())
return chunk.isLast() ? Content.Chunk.EOF : Content.Chunk.EMPTY;

ByteBuffer byteBuffer = chunk.getByteBuffer();
byte b = byteBuffer.get();
ByteBuffer byteBufferIn = chunk.getByteBuffer();
byte b = byteBufferIn.get();
if (b == '*')
return Content.Chunk.EMPTY;

byte lower = StringUtil.asciiToLowerCase(b);
return Content.Chunk.from(ByteBuffer.wrap(new byte[]{lower}), false);
RetainableByteBuffer bufferOut = bufferPool.acquire(1, true);
ByteBuffer byteBufferOut = bufferOut.getByteBuffer();
int pos = BufferUtil.flipToFill(byteBufferOut);
byteBufferOut.put(StringUtil.asciiToLowerCase(b));
BufferUtil.flipToFlush(byteBufferOut, pos);
return Content.Chunk.asChunk(byteBufferOut, false, bufferOut);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public Content.Chunk read()
// return a non-last transformed chunk to force more read() and transform().
if (transformedLast && !rawLast)
{
if (transformedChunk == Content.Chunk.EOF)
if (transformedChunk.isEmpty())
transformedChunk = Content.Chunk.EMPTY;
else if (!transformedFailure)
transformedChunk = Content.Chunk.asChunk(transformedChunk.getByteBuffer(), false, transformedChunk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ private ByteBuffer gzip(List<ByteBuffer> buffers, boolean finished) throws IOExc

private static class GZIPDecoder extends GZIPContentDecoder
{
public GZIPDecoder(ByteBufferPool bufferPool)
private GZIPDecoder(ByteBufferPool bufferPool)
{
super(bufferPool, IO.DEFAULT_BUFFER_SIZE);
}
Expand Down

0 comments on commit 72bb0b1

Please sign in to comment.