okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

Connection to MockWebServer takes 5 seconds if "Expect: 100-continue" and "chunkedStreamingMode" are set

Open phauer opened this issue 5 years ago • 3 comments

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

phauer avatar Mar 08 '19 15:03 phauer

Can fix.

swankjesse avatar Mar 09 '19 02:03 swankjesse

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?

andre161292 avatar Jun 14 '21 08:06 andre161292

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.

jsaulou avatar Nov 21 '22 15:11 jsaulou