hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: fluent - need to consume all content?
Date Fri, 30 Aug 2013 09:34:04 GMT
On Thu, 2013-08-29 at 15:34 -0700, Mike Wertheim wrote:
> I'm reading http://hc.apache.org/httpcomponents-client-ga/quickstart.html,
> which describes the lower-level (not fluent) httpclient API.
> 
> It says: "In order to ensure correct deallocation of system resources the
> user MUST either fully consume the response content  or abort
> request execution by calling HttpGet#releaseConnection()."
> 
> I am using the fluent API.  In the fluent API, I don't see any place in
> which my code would release a connection (since the connections seem to be
> managed under the covers).  Does that mean that my requests must always
> fully consume the response content?
> 

No, it does not. HTTP responses returned by HC fluent are not bound to
an active connection. There is no need to consume full response content
in order to release it. 

There is one catch, though. One must do _something_ with the request
result. If you just execute a request like that you will end up with a
resource leak.

---
Request.Get("http://targethost/homepage").execute();
// ignore response
---

At the very least you should do something like that
---
Request.Get("http://targethost/homepage").execute().returnContent();
---

or if you do not care about the result at all do
---
Request.Get("http://targethost/homepage").execute().discardContent();
---

> My code reads web pages up to a certain max number of bytes, and then
> stops.  Could this behavior be causing a resource leak?

You can still use normal HttpClient wire / context logging to find out
what is going on inside the connection manager and what stuff gets
transferred across the wire. HC fluent is merely a facade to HttpClient.

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message