Skip to content

Commit 7e8c430

Browse files
authored
fixed reading the data from the stream and fixed the size of chunks (#10409)
InputStream.read may read less bytes than actually are in the stream, this might corrupt the forwarded data. Also fixed the size of the chunks send after the initial chunk. [skip ci]
1 parent d1c5a43 commit 7e8c430

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

java/src/org/openqa/selenium/netty/server/ResponseConverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.openqa.selenium.netty.server;
1919

20+
import com.google.common.io.ByteStreams;
2021
import io.netty.buffer.Unpooled;
2122
import io.netty.channel.ChannelFuture;
2223
import io.netty.channel.ChannelHandlerContext;
@@ -59,7 +60,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
5960
// We may not know how large the response is, but figure it out if we can.
6061
byte[] ary = new byte[CHUNK_SIZE];
6162
InputStream is = seResponse.getContent().get();
62-
int byteCount = is.read(ary);
63+
int byteCount = ByteStreams.read(is, ary, 0, ary.length);
6364
// If there are no bytes left to read, then -1 is returned by read, and this is bad.
6465
byteCount = byteCount == -1 ? 0 : byteCount;
6566

@@ -84,7 +85,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
8485
// We need to write the first response.
8586
ctx.write(new DefaultHttpContent(Unpooled.wrappedBuffer(ary)));
8687

87-
HttpChunkedInput writer = new HttpChunkedInput(new ChunkedStream(is));
88+
HttpChunkedInput writer = new HttpChunkedInput(new ChunkedStream(is, CHUNK_SIZE));
8889
ChannelFuture future = ctx.write(writer);
8990
future.addListener(ignored -> {
9091
is.close();

0 commit comments

Comments
 (0)