Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
phauer opened this issue Mar 8, 2019 · 3 comments
Labels
bug Bug in existing code mockwebserver MockWebServer related
Milestone

Comments

@phauer
Copy link

phauer commented Mar 8, 2019

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 phauer added the bug Bug in existing code label Mar 8, 2019
@phauer phauer changed the title Connection to MockWebServer takes 5 seconds if "Expect: 100-continue" and "chunkedStreamingMode" is set Connection to MockWebServer takes 5 seconds if "Expect: 100-continue" and "chunkedStreamingMode" are set Mar 8, 2019
@swankjesse swankjesse added this to the Backlog milestone Mar 9, 2019
@swankjesse
Copy link
Collaborator

Can fix.

@andre161292
Copy link

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?

@yschimke yschimke added the mockwebserver MockWebServer related label Jun 28, 2021
@jsaulou
Copy link

jsaulou commented Nov 21, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code mockwebserver MockWebServer related
Projects
None yet
Development

No branches or pull requests

5 participants