Close streams on error paths

This commit is contained in:
Andrew Gaul 2012-03-21 15:56:11 -07:00 committed by Andrew Gaul
parent 6fda2580f5
commit 1040a5c779
3 changed files with 3 additions and 5 deletions

View File

@ -156,6 +156,7 @@ public abstract class BaseHttpCommandExecutorService<Q> implements HttpCommandEx
utils.logResponse(headerLog, response, "<<");
if (response.getPayload() != null && wire.enabled())
wire.input(response);
nativeRequest = null; // response took ownership of streams
int statusCode = response.getStatusCode();
if (statusCode >= 300) {
if (shouldContinue(response))

View File

@ -255,12 +255,9 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
}
/**
* Only disconnect if there is no content, as disconnecting will throw away unconsumed content.
*/
@Override
protected void cleanup(HttpURLConnection connection) {
if (connection != null && connection.getContentLength() == 0)
if (connection != null)
connection.disconnect();
}

View File

@ -201,7 +201,7 @@ public abstract class BaseRestClientExpectTest<S> {
@Override
public void cleanup(HttpRequest nativeResponse) {
if (nativeResponse.getPayload() != null)
if (nativeResponse != null && nativeResponse.getPayload() != null)
nativeResponse.getPayload().release();
}