fix: support 0 size read from stream (#539)
This commit is contained in:
@@ -45,6 +45,9 @@ public class Stream extends ChannelOwner {
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) {
|
||||
if (len == 0) {
|
||||
return 0;
|
||||
}
|
||||
JsonObject params = new JsonObject();
|
||||
params.addProperty("size", len);
|
||||
JsonObject json = sendMessage("read", params).getAsJsonObject();
|
||||
|
||||
@@ -367,6 +367,19 @@ public class TestDownload extends TestBase {
|
||||
page.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void streamShouldSupportZeroSizeRead() throws IOException {
|
||||
Page page = browser.newPage(new Browser.NewPageOptions().setAcceptDownloads(true));
|
||||
page.setContent("<a href='" + server.PREFIX + "/download'>download</a>");
|
||||
Download download = page.waitForDownload(() -> page.click("a"));
|
||||
|
||||
InputStream stream = download.createReadStream();
|
||||
byte[] b = new byte[1];
|
||||
int read = stream.read(b, 0, 0);
|
||||
assertEquals(0, read);
|
||||
page.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldDeleteDownloadsOnContextDestruction() {
|
||||
Page page = browser.newPage(new Browser.NewPageOptions().setAcceptDownloads(true));
|
||||
|
||||
Reference in New Issue
Block a user