/*
 * Copyright 2010 Ning, Inc.
 *
 * Ning licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 *
 */
package com.ning.http.client;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Represents a proxy server.
 */
public class ProxyServer {

    public enum Protocol {
        HTTP("http"), HTTPS("https"), NTLM("NTLM"), KERBEROS("KERBEROS"), SPNEGO("SPNEGO");

        private final String protocol;

        private Protocol(final String protocol) {
            this.protocol = protocol;
        }

        public String getProtocol() {
            return protocol;
        }

        @Override
        public String toString() {
            return getProtocol();
        }
    }

    private String encoding = "UTF-8";
    private final List<String> nonProxyHosts = new ArrayList<String>();
    private final Protocol protocol;
    private final String host;
    private final String principal;
    private final String password;
    private int port;
    private String ntlmDomain = System.getProperty("http.auth.ntlm.domain", "");

    private boolean isBasic = true;
    
    public boolean isBasic() {
		return isBasic;
	}

	public void setBasic(boolean isBasic) {
		this.isBasic = isBasic;
	}

	public ProxyServer(final Protocol protocol, final String host, final int port, String principal, String password) {
        this.protocol = protocol;
        this.host = host;
        this.port = port;
        this.principal = principal;
        this.password = password;
    }

    public ProxyServer(final String host, final int port, String principal, String password) {
        this(Protocol.HTTP, host, port, principal, password);
    }

    public ProxyServer(final Protocol protocol, final String host, final int port) {
        this(protocol, host, port, null, null);
    }

    public ProxyServer(final String host, final int port) {
        this(Protocol.HTTP, host, port, null, null);
    }

    public Protocol getProtocol() {
        return protocol;
    }

    public String getProtocolAsString() {
        return protocol.toString();
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    public String getPrincipal() {
        return principal;
    }

    public String getPassword() {
        return password;
    }

    public ProxyServer setEncoding(String encoding) {
        this.encoding = encoding;
        return this;
    }

    public String getEncoding() {
        return encoding;
    }

    public ProxyServer addNonProxyHost(String uri) {
        nonProxyHosts.add(uri);
        return this;
    }

    public ProxyServer removeNonProxyHost(String uri) {
        nonProxyHosts.remove(uri);
        return this;
    }

    public List<String> getNonProxyHosts() {
        return Collections.unmodifiableList(nonProxyHosts);
    }

    public ProxyServer setNtlmDomain(String ntlmDomain) {
        this.ntlmDomain = ntlmDomain;
        return this;
    }

    public String getNtlmDomain() {
        return ntlmDomain;
    }

    @Override
    public String toString() {
        return String.format("%s://%s:%d", protocol.toString(), host, port);
    }
}


@@ -645,16 +645,37 @@
 lient;%0A%0A
+import java.net.URI;%0A
 import j
@@ -694,16 +694,16 @@
 ayList;%0A
-
 import j
@@ -748,16 +748,67 @@
 .List;%0A%0A
+import com.ning.http.util.AsyncHttpProviderUtils;%0A%0A
 /**%0A * R
@@ -1310,47 +1310,8 @@
  %7D%0A%0A
-    private String encoding = %22UTF-8%22;%0A
     
@@ -1529,16 +1529,22 @@
 private 
+final 
 int port
@@ -1541,24 +1541,90 @@
 l int port;%0A
+    private final URI uri;%0A    private String encoding = %22UTF-8%22;%0A
     private 
@@ -2123,32 +2123,97 @@
 ord = password;%0A
+        this.uri = AsyncHttpProviderUtils.createUri(toString());%0A
     %7D%0A%0A    publi
@@ -3201,32 +3201,85 @@
 ncoding;%0A    %7D%0A%0A
+    public URI getURI() %7B%0A        return uri;%0A    %7D%0A%0A
     public Proxy
@@ -3864,68 +3864,44 @@
 urn 
-String.format(%22%25s://%25s:%25d%22, protocol.toString(), host,
+protocol + %22://%22 + host + %22:%22 +
  port
-)
 ;%0A  

Add getURI method on ProxyServer, close #253