From eaadc9e6bd8f02b3f93396e85313998646f80c7e Mon Sep 17 00:00:00 2001 From: jwilson Date: Sun, 15 Mar 2015 17:04:53 -0400 Subject: [PATCH] Relax expectations when streamed requests fail. We don't have machinery to recover from this when streamed requests fail, and we also don't have machinery to reliably detect when they will fail. This is sad. Fortunately the new API doesn't suffer this problem. --- .../internal/http/URLConnectionTest.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java index b1c80b01f..b9c679332 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java @@ -2570,7 +2570,6 @@ public final class URLConnectionTest { reusedConnectionFailsWithPost(TransferKind.END_OF_STREAM, 1024); } - // This test is ignored because we don't (yet) reliably recover for large request bodies. @Test public void postFailsWithBufferedRequestForLargeRequest() throws Exception { reusedConnectionFailsWithPost(TransferKind.END_OF_STREAM, 16384); } @@ -2603,14 +2602,24 @@ public final class URLConnectionTest { byte[] requestBody = new byte[requestSize]; new Random(0).nextBytes(requestBody); - connection = client.open(server.getUrl("/b")); - connection.setRequestMethod("POST"); - transferKind.setForRequest(connection, requestBody.length); - for (int i = 0; i < requestBody.length; i += 1024) { - connection.getOutputStream().write(requestBody, i, 1024); + for (int j = 0; j < 2; j++) { + try { + connection = client.open(server.getUrl("/b")); + connection.setRequestMethod("POST"); + transferKind.setForRequest(connection, requestBody.length); + for (int i = 0; i < requestBody.length; i += 1024) { + connection.getOutputStream().write(requestBody, i, 1024); + } + connection.getOutputStream().close(); + assertContent("B", connection); + break; + } catch (IOException socketException) { + // If there's a socket exception, this must have a streamed request body. + assertEquals(0, j); + assertTrue(transferKind == TransferKind.CHUNKED + || transferKind == TransferKind.FIXED_LENGTH); + } } - connection.getOutputStream().close(); - assertContent("B", connection); RecordedRequest requestA = server.takeRequest(); assertEquals("/a", requestA.getPath());