FileDocCategorySizeDatePackage
HttpConfiguration.javaAPI DocAndroid 1.5 API4789Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.internal.net.www.protocol.http

HttpConfiguration

public class HttpConfiguration extends Object
An HttpConfiguration contains all the details needed to create an http connection and to compare whether or not two connections are the same. An HttpConfiguration will either consist of a Proxy or a port number (int) and host name (String) or all three, depending on whether or not a Proxy is used and the type of Proxy it is. HttpConfiguration is used as a key by HttpConnectionManager to retrieve HttpConnections from its connection pool.

Fields Summary
private Proxy
proxy
private int
hostPort
private String
hostName
private URI
uri
Constructors Summary
public HttpConfiguration(URI uri)

        this.uri = uri;
        this.hostName = uri.getHost();
        this.hostPort = uri.getPort();
        if(hostPort == -1) {
            if(uri.getScheme().equals("https")) { //$NON-NLS-1$
                hostPort = 443;
            } else {
                hostPort = 80;
            }
        }
    
public HttpConfiguration(URI uri, Proxy proxy)

        this.uri = uri;
        this.proxy = proxy;
        if (proxy.type() == Proxy.Type.HTTP) {
            SocketAddress proxyAddr = proxy.address();
            if (!(proxyAddr instanceof InetSocketAddress)) {
               throw new IllegalArgumentException(Msg.getString(
                   "K0316", proxyAddr.getClass())); //$NON-NLS-1$
            }
            InetSocketAddress iProxyAddr = (InetSocketAddress) proxyAddr;
            this.hostName = iProxyAddr.getHostName();
            this.hostPort = iProxyAddr.getPort();
        } else {
            // using SOCKS proxy
            this.hostName = uri.getHost();
            this.hostPort = uri.getPort();
            if(hostPort == -1) {
                if(uri.getScheme().equals("https")) { //$NON-NLS-1$
                    hostPort = 443;
                } else {
                    hostPort = 80;
                }
            }
        }
        this.uri = uri;
        SocketAddress proxyAddr = proxy.address();
        if (!(proxyAddr instanceof InetSocketAddress)) {
           throw new IllegalArgumentException(Msg.getString(
               "K0316", proxyAddr.getClass())); //$NON-NLS-1$
        }
        InetSocketAddress iProxyAddr = (InetSocketAddress) proxyAddr;
        this.hostName = iProxyAddr.getHostName();
        this.hostPort = iProxyAddr.getPort();
    
Methods Summary
public booleanequals(java.lang.Object arg0)

        if(!(arg0 instanceof HttpConfiguration)) {
            return false;
        } else {
            HttpConfiguration config = (HttpConfiguration)arg0;
            if(config.proxy != null && proxy != null) {
                return config.proxy.equals(proxy) && uri.equals(config.uri);
            }
            return uri.equals(config.uri);
        }
    
public java.lang.StringgetHostName()
Returns the host name for this configuration, or null if an http Proxy is used

        return hostName;
    
public intgetHostPort()
Returns the port for this configuration, or 0 if an http Proxy is used

        return hostPort;
    
public java.net.ProxygetProxy()
Returns the Proxy for this configuration, or null if a proxy is not used

        return proxy;
    
public inthashCode()

        return uri.hashCode();
    
public booleanusesProxy()
Returns true if this configuration uses a Proxy

        return proxy != null;