You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by yoosh <ev...@gmail.com> on 2010/12/01 19:50:28 UTC

How to prevent HttpClient from downloading large files?

Hi, 

I've searched the forum:

http://old.nabble.com/Opening-streaming-URL-td11290919.html#a11344350
http://old.nabble.com/Opening-streaming-URL-td11290919.html#a11344350 

based on the above, I still don't understand fully that:

entity.getContent() will start downloading the content/body since
httpclient-3.x above or as soon as I call httpclient.execute(..) it will
download the whole response including the body. 

I'm using Httpclient-4.0.1, and what I have so far is I do a HEAD call, and
check content length if its not too large, then proceed a GET call, and do
something with the body from entity.getContent() which is very expensive.

Could anyone please explain and point out to a better solution as I want to
avoid an extra call (i.e. say just do GET call)?

Thanks.
-- 
View this message in context: http://old.nabble.com/How-to-prevent-HttpClient-from-downloading-large-files--tp30352097p30352097.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


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


Re: How to prevent HttpClient from downloading large files?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2010-12-01 at 10:50 -0800, yoosh wrote:
> Hi, 
> 
> I've searched the forum:
> 
> http://old.nabble.com/Opening-streaming-URL-td11290919.html#a11344350
> http://old.nabble.com/Opening-streaming-URL-td11290919.html#a11344350 
> 
> based on the above, I still don't understand fully that:
> 
> entity.getContent() will start downloading the content/body since
> httpclient-3.x above or as soon as I call httpclient.execute(..) it will
> download the whole response including the body. 
> 
> I'm using Httpclient-4.0.1, and what I have so far is I do a HEAD call, and
> check content length if its not too large, then proceed a GET call, and do
> something with the body from entity.getContent() which is very expensive.
> 
> Could anyone please explain and point out to a better solution as I want to
> avoid an extra call (i.e. say just do GET call)?
> 
> Thanks.

Just do one GET, look at the content-length value if known, read as much
(or as little) data as needed and then abort the request. It is often
cheaper to close non-SSL connections than re-use them.

Oleg


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