Skip to content

Commit 45f8142

Browse files
committed
make users close the response
1 parent ac8e24b commit 45f8142

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

google-http-client-apache-v5/src/main/java/com/google/api/client/http/apache/v5/Apache5HttpResponse.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import com.google.api.client.http.LowLevelHttpResponse;
1818
import java.io.IOException;
1919
import java.io.InputStream;
20+
import java.util.logging.Level;
21+
import java.util.logging.Logger;
2022
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
2123
import org.apache.hc.core5.http.ClassicHttpResponse;
2224
import org.apache.hc.core5.http.Header;
@@ -25,6 +27,7 @@
2527

2628
final class Apache5HttpResponse extends LowLevelHttpResponse {
2729

30+
private static final Logger LOGGER = Logger.getLogger(Apache5HttpResponse.class.getName());
2831
private final HttpUriRequestBase request;
2932
private final ClassicHttpResponse response;
3033
private final Header[] allHeaders;
@@ -99,6 +102,17 @@ public String getHeaderValue(int index) {
99102
/** Aborts execution of the request. */
100103
@Override
101104
public void disconnect() {
105+
close();
106+
}
107+
108+
public void close() {
102109
request.abort();
110+
try {
111+
response.close();
112+
} catch (IOException e) {
113+
// the close() method contract won't allow us to declare a thrown exception. Here we just log
114+
// the error
115+
LOGGER.log(Level.SEVERE, "Error occurred when closing the response", e);
116+
}
103117
}
104118
}

0 commit comments

Comments
 (0)