Skip to content

Commit c21e745

Browse files
authored
Revert the order of stream closure and disconnect (#1427)
1 parent fc2f668 commit c21e745

File tree

2 files changed

+1
-37
lines changed

2 files changed

+1
-37
lines changed

google-http-client-apache-v2/src/test/java/com/google/api/client/http/apache/v2/ApacheHttpTransportTest.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -321,38 +321,4 @@ public void handle(HttpExchange httpExchange) throws IOException {
321321
private boolean isWindows() {
322322
return System.getProperty("os.name").startsWith("Windows");
323323
}
324-
325-
@Test(timeout = 10_000L)
326-
public void testDisconnectShouldNotWaitToReadResponse() throws IOException {
327-
// This handler waits for 100s before returning writing content. The test should
328-
// timeout if disconnect waits for the response before closing the connection.
329-
final HttpHandler handler =
330-
new HttpHandler() {
331-
@Override
332-
public void handle(HttpExchange httpExchange) throws IOException {
333-
byte[] response = httpExchange.getRequestURI().toString().getBytes();
334-
httpExchange.sendResponseHeaders(200, response.length);
335-
336-
// Sleep for longer than the test timeout
337-
try {
338-
Thread.sleep(100_000);
339-
} catch (InterruptedException e) {
340-
throw new IOException("interrupted", e);
341-
}
342-
try (OutputStream out = httpExchange.getResponseBody()) {
343-
out.write(response);
344-
}
345-
}
346-
};
347-
348-
try (FakeServer server = new FakeServer(handler)) {
349-
HttpTransport transport = new ApacheHttpTransport();
350-
GenericUrl testUrl = new GenericUrl("http://localhost/foo//bar");
351-
testUrl.setPort(server.getPort());
352-
com.google.api.client.http.HttpResponse response =
353-
transport.createRequestFactory().buildGetRequest(testUrl).execute();
354-
// disconnect should not wait to read the entire content
355-
response.disconnect();
356-
}
357-
}
358324
}

google-http-client/src/main/java/com/google/api/client/http/HttpResponse.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,10 +442,8 @@ public void ignore() throws IOException {
442442
* @since 1.4
443443
*/
444444
public void disconnect() throws IOException {
445-
// Close the connection before trying to close the InputStream content. If you are trying to
446-
// disconnect, we shouldn't need to read any further content.
447-
response.disconnect();
448445
ignore();
446+
response.disconnect();
449447
}
450448

451449
/**

0 commit comments

Comments
 (0)