Skip to content

Commit

Permalink
Issue #5605 - java.io.IOException: unconsumed input during http reque…
Browse files Browse the repository at this point in the history
…st parsing.

Writing content in separate writes may result in the server
only reading partial content, producing a response with
`Connection: close` that would cause the client socket to
stop receiving data for the next response, failing the test.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Nov 18, 2020
1 parent f533380 commit e3e5c2e
Showing 1 changed file with 11 additions and 6 deletions.
Expand Up @@ -22,6 +22,7 @@
import java.io.InputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -147,8 +148,7 @@ Socket newClientIdle(byte[] post, TestHandler handler) throws Exception
handler.latch = new CountDownLatch(1);
final int port = connector.getLocalPort();
Socket client = new Socket("127.0.0.1", port);
client.getOutputStream().write(post);
client.getOutputStream().write(BODY_67890);
client.getOutputStream().write(concat(post, BODY_67890));
client.getOutputStream().flush();
assertTrue(handler.latch.await(5, TimeUnit.SECONDS));

Expand All @@ -163,8 +163,7 @@ Socket newClientIdle(byte[] post, TestHandler handler) throws Exception
void assertAvailable(Socket client, byte[] post, TestHandler handler) throws Exception
{
handler.latch = new CountDownLatch(1);
client.getOutputStream().write(post);
client.getOutputStream().write(BODY_67890);
client.getOutputStream().write(concat(post, BODY_67890));
client.getOutputStream().flush();
assertTrue(handler.latch.await(5, TimeUnit.SECONDS));

Expand All @@ -188,8 +187,7 @@ Future<Integer> backgroundUnavailable(Socket client, byte[] post, ContextHandler
Thread.sleep(100);
}

client.getOutputStream().write(post);
client.getOutputStream().write(BODY_67890);
client.getOutputStream().write(concat(post, BODY_67890));
client.getOutputStream().flush();
HttpTester.Response response = HttpTester.parseResponse(client.getInputStream());

Expand Down Expand Up @@ -281,6 +279,13 @@ void backgroundComplete(Socket client, TestHandler handler) throws Exception
}).start();
}

private byte[] concat(byte[] bytes1, byte[] bytes2)
{
byte[] bytes = Arrays.copyOf(bytes1, bytes1.length + bytes2.length);
System.arraycopy(bytes2, 0, bytes, bytes1.length, bytes2.length);
return bytes;
}

@Test
public void testNotGraceful() throws Exception
{
Expand Down

0 comments on commit e3e5c2e

Please sign in to comment.