Skip to content

Commit 87bf33c

Browse files
author
Stephane Landelle
committed
Drop InputStreamBodyGenerator marking strategy, close AsyncHttpClient#760
1 parent f80dc37 commit 87bf33c

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ private static class InputStreamBody implements Body {
5757

5858
private InputStreamBody(InputStream inputStream) {
5959
this.inputStream = inputStream;
60-
if (inputStream.markSupported()) {
61-
inputStream.mark(0);
62-
} else {
63-
LOGGER.info("inputStream.markSupported() not supported. Some features will not work.");
64-
}
6560
}
6661

6762
public long getContentLength() {
@@ -82,10 +77,6 @@ public long read(ByteBuffer buffer) throws IOException {
8277

8378
if (read > 0) {
8479
buffer.put(chunk, 0, read);
85-
} else {
86-
if (inputStream.markSupported()) {
87-
inputStream.reset();
88-
}
8980
}
9081
return read;
9182
}

api/src/test/java/org/asynchttpclient/async/ChunkingTest.java

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
import static org.testng.Assert.assertTrue;
1919
import static org.testng.FileAssert.fail;
2020

21+
import java.io.BufferedInputStream;
22+
import java.io.FileInputStream;
23+
import java.io.InputStream;
24+
2125
import org.asynchttpclient.AsyncHttpClient;
2226
import org.asynchttpclient.AsyncHttpClientConfig;
2327
import org.asynchttpclient.Request;
@@ -26,9 +30,6 @@
2630
import org.asynchttpclient.generators.InputStreamBodyGenerator;
2731
import org.testng.annotations.Test;
2832

29-
import java.io.BufferedInputStream;
30-
import java.io.FileInputStream;
31-
3233
/**
3334
* Test that the url fetcher is able to communicate via a proxy
3435
*
@@ -37,28 +38,36 @@
3738
abstract public class ChunkingTest extends AbstractBasicTest {
3839
// So we can just test the returned data is the image,
3940
// and doesn't contain the chunked delimeters.
41+
@Test()
42+
public void testBufferLargerThanFile() throws Throwable {
43+
doTest(new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE), 400000));
44+
}
45+
46+
@Test()
47+
public void testBufferSmallThanFile() throws Throwable {
48+
doTest(new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE)));
49+
}
4050

41-
/**
42-
* Tests that the custom chunked stream result in success and content returned that is unchunked
43-
*/
4451
@Test()
45-
public void testCustomChunking() throws Exception {
46-
AsyncHttpClientConfig.Builder bc = new AsyncHttpClientConfig.Builder();
52+
public void testDirectFile() throws Throwable {
53+
doTest(new FileInputStream(LARGE_IMAGE_FILE));
54+
}
4755

48-
bc.setAllowPoolingConnections(true);
49-
bc.setMaxConnectionsPerHost(1);
50-
bc.setMaxConnections(1);
51-
bc.setConnectTimeout(1000);
52-
bc.setRequestTimeout(1000);
53-
bc.setFollowRedirect(true);
56+
public void doTest(InputStream is) throws Throwable {
57+
AsyncHttpClientConfig.Builder bc = new AsyncHttpClientConfig.Builder()//
58+
.setAllowPoolingConnections(true)//
59+
.setMaxConnectionsPerHost(1)//
60+
.setMaxConnections(1)//
61+
.setConnectTimeout(1000)//
62+
.setRequestTimeout(1000)
63+
.setFollowRedirect(true);
5464

5565
AsyncHttpClient c = getAsyncHttpClient(bc.build());
5666
try {
5767

5868
RequestBuilder builder = new RequestBuilder("POST");
5969
builder.setUrl(getTargetUrl());
60-
// made buff in stream big enough to mark.
61-
builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE), 400000)));
70+
builder.setBody(new InputStreamBodyGenerator(is));
6271

6372
Request r = builder.build();
6473

0 commit comments

Comments
 (0)