Skip to content

Commit b4049e0

Browse files
committed
close() response only, emit getContent() exception
1 parent ff5c209 commit b4049e0

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

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

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,12 @@ final class Apache5HttpResponse extends LowLevelHttpResponse {
3232
private final ClassicHttpResponse response;
3333
private final Header[] allHeaders;
3434
private final HttpEntity entity;
35-
private final Apache5ResponseContent content;
3635

3736
Apache5HttpResponse(HttpUriRequestBase request, ClassicHttpResponse response) {
3837
this.request = request;
3938
this.response = response;
4039
this.allHeaders = response.getHeaders();
4140
this.entity = response.getEntity();
42-
Apache5ResponseContent contentValue = null;
43-
if (entity != null) {
44-
try {
45-
contentValue = new Apache5ResponseContent(entity.getContent(), response);
46-
} catch (IOException ex) {
47-
LOGGER.log(Level.SEVERE, "Error when obtaining content from the response", ex);
48-
}
49-
}
50-
this.content = contentValue;
5141
}
5242

5343
@Override
@@ -57,7 +47,7 @@ public int getStatusCode() {
5747

5848
@Override
5949
public InputStream getContent() throws IOException {
60-
return content;
50+
return new Apache5ResponseContent(entity.getContent(), response);
6151
}
6252

6353
@Override
@@ -109,12 +99,11 @@ public String getHeaderValue(int index) {
10999
public void disconnect() {
110100
request.abort();
111101
try {
112-
// this call also close the response
113-
content.close();
102+
response.close();
114103
} catch (IOException e) {
115104
// the close() method contract won't allow us to declare a thrown exception. Here we just log
116105
// the error
117-
LOGGER.log(Level.SEVERE, "Error occurred when closing the content", e);
106+
LOGGER.log(Level.SEVERE, "Error occurred when closing the response", e);
118107
}
119108
}
120109
}

0 commit comments

Comments
 (0)