/**
 * Copyright (C) 2013 Cloudant
 *
 * Copyright (C) 2011 Ahmed Yehia (ahmed.yehia.m@gmail.com)
 *
 * Licensed 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.cloudant.mazha;

import com.google.common.base.Strings;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CouchConfig {

    // The root URI for the database
    // This could be in the form http://host/database-name
    // but is treated as an opaque URI to correctly handle
    // situations where the request is forwarded eg through
    // a reverse proxy
    private URI rootUri;

    // Timeout to wait for a response, in milliseconds. Defaults to 0 (no timeout).
	private int socketTimeout = 30000;

    // Timeout to establish a connection, in milliseconds. Defaults to 0 (no timeout).
    private int connectionTimeout = 30000;

    // Max connections.
    private int maxConnections = 5;

    private int bufferSize = 1024 * 8;

    private boolean staleConnectionCheckingEnabled = Boolean.FALSE;

    private boolean handleRedirectEnabled = Boolean.FALSE;

    // Optional custom headers
    private Map<String, String> customHeaders;

    public boolean isStaleConnectionCheckingEnabled() {
        return staleConnectionCheckingEnabled;
    }

    public void setStaleConnectionCheckingEnabled(boolean staleConnectionCheckingEnabled) {
        this.staleConnectionCheckingEnabled = staleConnectionCheckingEnabled;
    }

    public boolean isHandleRedirectEnabled() {
        return handleRedirectEnabled;
    }

    public void setHandleRedirectEnabled(boolean handleRedirectEnabled) {
        this.handleRedirectEnabled = handleRedirectEnabled;
    }

    public int getBufferSize() {
        return bufferSize;
    }

    public void setBufferSize(int bufferSize) {
        this.bufferSize = bufferSize;
    }

    public CouchConfig(URI rootUri) {
        this.rootUri = rootUri;
    }

	public int getSocketTimeout() {
		return socketTimeout;
	}

	public int getConnectionTimeout() {
		return connectionTimeout;
	}

	public int getMaxConnections() {
		return maxConnections;
	}

	public void setSocketTimeout(int socketTimeout) {
		this.socketTimeout = socketTimeout;
	}

	public void setConnectionTimeout(int connectionTimeout) {
		this.connectionTimeout = connectionTimeout;
	}

	public void setMaxConnections(int maxConnections) {
		this.maxConnections = maxConnections;
	}

    public Map<String, String> getCustomHeaders() {
        return customHeaders;
    }

    public void setCustomHeaders(Map<String, String> customHeaders) {
        List<String> prohibitedHeaders = Arrays.asList("www-authenticate", "host", "connection",
                "content-type", "accept", "content-length");
        for (Map.Entry<String, String> header : customHeaders.entrySet()) {
            if (prohibitedHeaders.contains(header.getKey().toLowerCase())) {
                throw new IllegalArgumentException("Bad optional HTTP header: " + header);
            }
        }
        this.customHeaders = customHeaders;
    }

    public URI getRootUri() {
        return rootUri;
    }
}

@@ -690,147 +690,45 @@
 ort 
-com.google.common.base.Strings;%0A%0Aimport java.net.URI;%0Aimport java.net.URISyntaxException;%0Aimport java.util.Arrays;%0Aimport java.util.HashMap
+java.net.URI;%0Aimport java.util.Arrays
 ;%0Aim
@@ -1074,1808 +1074,154 @@
  // 
-Timeout to wait for a response, in milliseconds. Defaults to 0 (no timeout).%0A%09private int socketTimeout = 30000;%0A%0A    // Timeout to establish a connection, in milliseconds. Defaults to 0 (no timeout).%0A    private int connectionTimeout = 30000;%0A%0A    // Max connections.%0A    private int maxConnections = 5;%0A%0A    private int bufferSize = 1024 * 8;%0A%0A    private boolean staleConnectionCheckingEnabled = Boolean.FALSE;%0A%0A    private boolean handleRedirectEnabled = Boolean.FALSE;%0A%0A    // Optional custom headers%0A    private Map%3CString, String%3E customHeaders;%0A%0A    public boolean isStaleConnectionCheckingEnabled() %7B%0A        return staleConnectionCheckingEnabled;%0A    %7D%0A%0A    public void setStaleConnectionCheckingEnabled(boolean staleConnectionCheckingEnabled) %7B%0A        this.staleConnectionCheckingEnabled = staleConnectionCheckingEnabled;%0A    %7D%0A%0A    public boolean isHandleRedirectEnabled() %7B%0A        return handleRedirectEnabled;%0A    %7D%0A%0A    public void setHandleRedirectEnabled(boolean handleRedirectEnabled) %7B%0A        this.handleRedirectEnabled = handleRedirectEnabled;%0A    %7D%0A%0A    public int getBufferSize() %7B%0A        return bufferSize;%0A    %7D%0A%0A    public void setBufferSize(int bufferSize) %7B%0A        this.bufferSize = bufferSize;%0A    %7D%0A%0A    public CouchConfig(URI rootUri) %7B%0A        this.rootUri = rootUri;%0A    %7D%0A%0A%09public int getSocketTimeout() %7B%0A%09%09return socketTimeout;%0A%09%7D%0A%0A%09public int getConnectionTimeout() %7B%0A%09%09return connectionTimeout;%0A%09%7D%0A%0A%09public int getMaxConnections() %7B%0A%09%09return maxConnections;%0A%09%7D%0A%0A%09public void setSocketTimeout(int socketTimeout) %7B%0A%09%09this.socketTimeout = socketTimeout;%0A%09%7D%0A%0A%09public void setConnectionTimeout(int connectionTimeout) %7B%0A%09%09this.connectionTimeout = connectionTimeout;%0A%09%7D%0A%0A%09public void setMaxConnections(int maxConnections) %7B%0A%09%09this.maxConnections = maxConnections;%0A%09
+Optional custom headers%0A    private Map%3CString, String%3E customHeaders;%0A%0A    public CouchConfig(URI rootUri) %7B%0A        this.rootUri = rootUri;%0A    
 %7D%0A%0A 

Clean up CouchConfig