package org.bench4q.recorder.httpcapture.generator;

import java.util.HashMap;

public class ResponseHeader {
	public static HashMap<String, String> MIME_TYPE = new HashMap<String, String>() {
		private static final long serialVersionUID = 1L;

		{
			put("text/plain", "text/plain");
			put("text/html", "text/html");
			put("text/comma-separated-values", "text/comma-separated-values");
		}
	};
	private int respCode;
	private String contentType;
	private String charset;
	private String contentEncoding;
	private int contentLength;
	private String transferEncoding;
	
	public int getRespCode() {
		return respCode;
	}

	public void setRespCode(int respCode) {
		this.respCode = respCode;
	}

	public String getContentType() {
		return contentType;
	}

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

	public String getCharset() {
		return charset == null ? "utf-8":charset;
	}

	public void setCharset(String charset) {
		this.charset = charset;
	}

	public String getContentEncoding() {
		return contentEncoding;
	}

	public void setContentEncoding(String contentEncoding) {
		this.contentEncoding = contentEncoding;
	}

	public int getContentLength() {
		return contentLength;
	}

	public void setContentLength(int contentLength) {
		this.contentLength = contentLength;
	}

	boolean isValidResponseHeader() {
		return (getContentType() != null)
				&& (MIME_TYPE.containsKey(getContentType()))
				&& (getRespCode() != -1);
	}

	boolean isHtmlContentType() {
		return getContentType().toLowerCase().contains("text/html");
	}

	boolean isGoodRequest() {
		return this.getRespCode() == 200;
//		return this.getRespCode().startsWith("200");
	}

	public String getTransferEncoding() {
		return transferEncoding;
	}

	public void setTransferEncoding(String transferEncoding) {
		this.transferEncoding = transferEncoding;
	}
}
