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 John Corro <Jo...@cornerstone.net> on 2006/05/24 22:16:20 UTC

Handling HTTP Keep-Alives

  
I've been noticing that I'm receiving Keep-Alive headers from a server I'm trying to access.  I was looking for any built-in methods that will tell me the status of this header flag and the closest thing I could find was "HttpMethodBase.shouldCloseConnection()", but that's protected.  Is there a specific reason this isn't given a "public" scope?  
I would like to be able to tell if a connection should be kept alive or not (without manually having to look for the header, etc) so that I don't explicitly close it via a "releaseConnection()" when I've completed executing the http call.  To the best of my knowledge a call to "releaseConnection()" will cause the connection to close without regard of any Keep-Alive header values - please correct me if this understanding is wrong.
 
 
John M. Corro
www.cornerstone.net
Cornerstone Consulting, Inc
731 N. Jackson Street, Suite 600 
Milwaukee, WI 53202
(414) 212-3500

Re: Handling HTTP Keep-Alives

Posted by Roland Weber <ht...@dubioso.net>.
Hello John,

> I would like to be able to tell if a connection should be kept alive or not
> (without manually having to look for the header, etc) so that
> I don't explicitly close it via a "releaseConnection()" when I've
> completed executing the http call.

You *always* have to call releaseConnection when you're done with a request!
It does *not* close the connection, it gives the connection back to the pool.
If you don't do that, the connection can never be used again, kept alive or
not!

> To the best of my knowledge a call to "releaseConnection()" will
> cause the connection to close without regard of any Keep-Alive header values
> - please correct me if this understanding is wrong.

Your understanding is wrong. releaseConnection() will give the connection
back to the pool, for use by another request. The pool implementation,
that is the connection manager Oleg mentioned, will decide whether the
connection gets closed or is kept alive. The connection managers shipped
with HttpClient do consider Keep-Alive headers and HTTP version to make
that decision.

cheers,
  Roland

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


Re: Handling HTTP Keep-Alives

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2006-05-24 at 15:16 -0500, John Corro wrote:
>   I've been noticing that I'm receiving Keep-Alive headers from a server I'm trying to access.  I was looking for any built-in methods that will tell me the status of this header flag and the closest thing I could find was "HttpMethodBase.shouldCloseConnection()", but that's protected.  Is there a specific reason this isn't given a "public" scope?  
> I would like to be able to tell if a connection should be kept alive or not (without manually having to look for the header, etc) so that I don't explicitly close it via a "releaseConnection()" when I've completed executing the http call.  To the best of my knowledge a call to "releaseConnection()" will cause the connection to close without regard of any Keep-Alive header values - please correct me if this understanding is wrong.

John,

HttpClient always keeps connection open per default if they can be kept
alive. Please consider implementing a custom connection manager if you
want to exert a greater control over the connection management process.

Hope this helps

Oleg


>  
> 
> John M. Corro
> www.cornerstone.net
> Cornerstone Consulting, Inc
> 731 N. Jackson Street, Suite 600 
> Milwaukee, WI 53202
> (414) 212-3500


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