HTTPResource should close HttpResponse

Description

Was looking at OSJ-44. Opening a new issue to track this here.

In HttpClient v4, it's required to close the HttpResponse instance and/or content stream, as documented here:

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e145

This should be easy for most methods here.

Not sure about the getInputStream(). It's currently directly returning the entity content stream. The caller can close the stream, but as documented I think that's intentionally going to leave the connection option. Since the caller doesn't get the HttpResponse back, there's no way it can close that. This aspect needs more research.

Environment

None

Activity

Tom Zeller 
November 26, 2014 at 7:18 AM

Resolving after assigning fix version.

Tom Zeller 
November 26, 2014 at 7:17 AM

Reopening to assign fix version.

Brent Putman 
November 19, 2014 at 12:02 AM

Implemented response closing with a finally block as above.

Implemented getInputStream() to return the response wrapped in InputStream impl that closes the stream and response on close().

Brent Putman 
September 27, 2014 at 1:55 AM

Or duh, we could do what v2 HttpResource does and return a specialized impl of InputStream that gets constructed with the HttpResponse and does the right thing on close(). That seems like the right solution.

Brent Putman 
September 27, 2014 at 1:45 AM

On the getInputStream(), maybe it should internally consume the entire content body and place into a buffer, close the HttpResponse connection, and then return the InputStream to the buffer. That could be expensive memory-wise if the content is large, but I'm not seeing another way at the moment to get the connection closed and still be able to hand back the InputStream.

Fixed

Details

Assignee

Reporter

Fix versions

Affects versions

Created September 27, 2014 at 1:34 AM
Updated April 21, 2016 at 5:05 PM
Resolved November 26, 2014 at 7:18 AM