All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ovh.ws.jsonizer.api.http.HttpClient Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2012, OVH. All rights reserved.
 *
 * 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.ovh.ws.jsonizer.api.http;

import static com.ovh.ws.jsonizer.api.base.OvhObject.checkNotNull;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

public abstract class HttpClient {

	private Map headers = new HashMap();
	private String protocol;
	private String host;
	private int port = -1;

	public Map getHeaders() {
		return headers;
	}

	/**
	 * Set header that will be added to all requests this client makes (before sending).
	 * 
	 * @param header
	 *            the name of the header
	 * @param value
	 *            the contents of the header
	 */
	public void addHeader(String header, String value) {
		headers.put(header, value);
	}

	public void removeHeader(String header) {
		headers.remove(header);
	}

	public String getProtocol() {
		return protocol;
	}

	public void setProtocol(String protocol) {
		this.protocol = protocol;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public void setHost(OvhHost host) {
		checkNotNull(host, "host is required");
		this.host = host.getValue();
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public abstract SyncWebResource resource(URI uri);

	public abstract AsyncWebResource asyncResource(URI uri);

	/**
	 * Set the User-Agent header.
	 */
	public abstract void setUserAgent(String userAgent);

	/**
	 * Set the read timeout interval, in milliseconds.
	 */
	public abstract void setTimeout(Integer interval);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy