package org.bench4q.agent.plugin.basic.http;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.httpclient.Header;
import org.bench4q.agent.plugin.basic.PluginReturn;

/***
 * the contentLength's unit is Byte
 * 
 * @author coderfengyun
 * 
 */
public class HttpReturn extends PluginReturn {
	private String url;
	private int statusCode;
	private long contentLength;
	private String contentType;
	private Header[] headers;

	public int getStatusCode() {
		return statusCode;
	}

	private void setStatusCode(int statusCode) {
		this.statusCode = statusCode;
	}

	public long getContentLength() {
		return contentLength;
	}

	private void setContentLength(long contentLength) {
		this.contentLength = contentLength;
	}

	public String getContentType() {
		return contentType;
	}

	private void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public Header[] getHeaders() {
		return headers;
	}

	private void setHeaders(Header[] headers) {
		this.headers = headers;
	}

	public String getUrl() {
		return url;
	}

	private void setUrl(String url) {
		this.url = url;
	}

	public HttpReturn(boolean success, int statusCode, long contentLength,
			String contentType) {
		super(success);
		this.setStatusCode(statusCode);
		this.setContentLength(contentLength);
		this.setContentType(contentType);
	}

	/**
	 * 
	 * @param success
	 * @param responseCode
	 * @param contentLength
	 * @param contentType
	 * @param responseHeaders
	 */
	public HttpReturn(boolean success, int responseCode, String url,
			long contentLength, String contentType, Header[] responseHeaders) {
		this(success, responseCode, contentLength, contentType);
		this.setHeaders(responseHeaders);
		this.setUrl(url);
	}

	public Map<String, String> getExtraResult() {
		Map<String, String> result = new HashMap<String, String>();
		result.put("contentLength", this.getContentLength() + "");
		result.put("contentType", this.getContentType());
		result.put("statusCode", this.getStatusCode() + "");
		return result;
	}
}
