okhttp
okhttp copied to clipboard
Connection to MockWebServer takes 5 seconds if "Expect: 100-continue" and "chunkedStreamingMode" are set
Hi,
when an HttpURLConnection
to a MockWebServer is configured with
-
connection.setRequestProperty("Expect", "100-continue")
and -
connection.setChunkedStreamingMode(0);
(or any other number)
the connection.getOutputStream()
takes 5 seconds before it returns.
I created a small test that reproduces this issue:
public class HangingMockWebServerTest {
@Test
public void foo() throws IOException {
MockWebServer server = new MockWebServer();
server.start();
server.enqueue(new MockResponse());
String url = server.url("foo").toString();
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
// relevant line 1:
connection.setRequestProperty("Expect", "100-continue");
connection.setDoOutput(true);
// relevant line 2:
connection.setChunkedStreamingMode(0); //or any other number
OutputStream output = connection.getOutputStream(); // takes 5 seconds!
try (PrintWriter writer = new PrintWriter(output)) {
writer.write("Super!");
}
}
}
If you remove one or both configurations, the test is fast again.
You may wonder, why I set those headers. I have to use the tus-client-java library, which does this.
I hope, this can be fixed.
Kind Regards, Philipp
Can fix.
I'm using the MockWebServer as a simple S3 mock in my integration test. As the S3 SDK makes use of the Expect: 100-continue
-Header too, this is an issue for me as well. It works, but tests are taking way more time than they'd normally need.
Is there any way to circumvent this problem?
I am in the same situation as @andre161292. We have an internal library making use of the Expect: 100-continue
header.
Out tests pass but they take much longer that they should.
A fix or workaround would be greatly appreciated.