FileDocCategorySizeDatePackage
DefaultConnectionKeepAliveStrategy.javaAPI DocAndroid 1.5 API2770Wed May 06 22:41:10 BST 2009org.apache.http.impl.client

DefaultConnectionKeepAliveStrategy

public class DefaultConnectionKeepAliveStrategy extends Object implements ConnectionKeepAliveStrategy
Default implementation of a strategy deciding duration that a connection can remain idle. The default implementation looks solely at the 'Keep-Alive' header's timeout token.
author
Sam Berlin
version
$Revision: $
since
4.0

Fields Summary
Constructors Summary
Methods Summary
public longgetKeepAliveDuration(org.apache.http.HttpResponse response, org.apache.http.protocol.HttpContext context)

        if (response == null) {
            throw new IllegalArgumentException("HTTP response may not be null");
        }
        HeaderElementIterator it = new BasicHeaderElementIterator(
                response.headerIterator(HTTP.CONN_KEEP_ALIVE));
        while (it.hasNext()) {
            HeaderElement he = it.nextElement();
            String param = he.getName(); 
            String value = he.getValue();
            if (value != null && param.equalsIgnoreCase("timeout")) {
                try {
                    return Long.parseLong(value) * 1000;
                } catch(NumberFormatException ignore) {
                }
            }
        }
        return -1;