/*
	ZazouMiniWebServer

	Copyright (C) 2003-2011 Xavier Garreau <xavier@xgarreau.org>

	This file is part of ZazouMiniWebServer.

    ZazouMiniWebServer is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    ZazouMiniWebServer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ZazouMiniWebServer; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
	
#include "stdafx.h"
#include "ZMWSHTTPUtils.h"


std::string ZMWSHTTPUtils::defaultHTTPResp =  "No reason for this code :/";

ZMWSHTTPUtils::ZMWSHTTPUtils(void){
	http_responses.insert(HTTP_RESPONSE(100, "Continue"));
	http_responses.insert(HTTP_RESPONSE(101, "Switching Protocols"));
	http_responses.insert(HTTP_RESPONSE(200, "OK")); 
	http_responses.insert(HTTP_RESPONSE(201, "Created"));
	http_responses.insert(HTTP_RESPONSE(202, "Accepted"));
	http_responses.insert(HTTP_RESPONSE(203, "Non-Authoritative Information"));
	http_responses.insert(HTTP_RESPONSE(204, "No Content"));
	http_responses.insert(HTTP_RESPONSE(205, "Reset Content"));
	http_responses.insert(HTTP_RESPONSE(206, "Partial Content"));
	http_responses.insert(HTTP_RESPONSE(300, "Multiple Choices"));
	http_responses.insert(HTTP_RESPONSE(301, "Moved Permanently"));
	http_responses.insert(HTTP_RESPONSE(302, "Found"));
	http_responses.insert(HTTP_RESPONSE(303, "See Other"));
	http_responses.insert(HTTP_RESPONSE(304, "Not Modified"));
	http_responses.insert(HTTP_RESPONSE(305, "Use Proxy"));
	http_responses.insert(HTTP_RESPONSE(306, "(Unused)"));
	http_responses.insert(HTTP_RESPONSE(307, "Temporary Redirect"));
	http_responses.insert(HTTP_RESPONSE(400, "Bad Request"));
	http_responses.insert(HTTP_RESPONSE(401, "Unauthorized"));
	http_responses.insert(HTTP_RESPONSE(402, "Payment Required"));
	http_responses.insert(HTTP_RESPONSE(403, "Forbidden"));
	http_responses.insert(HTTP_RESPONSE(404, "Not Found"));
	http_responses.insert(HTTP_RESPONSE(405, "Method Not Allowed"));
	http_responses.insert(HTTP_RESPONSE(406, "Not Acceptable"));
	http_responses.insert(HTTP_RESPONSE(407, "Proxy Authentication Required"));
	http_responses.insert(HTTP_RESPONSE(408, "Request Timeout"));
	http_responses.insert(HTTP_RESPONSE(409, "Conflict"));
	http_responses.insert(HTTP_RESPONSE(410, "Gone"));
	http_responses.insert(HTTP_RESPONSE(411, "Length Required"));
	http_responses.insert(HTTP_RESPONSE(412, "Precondition Failed"));
	http_responses.insert(HTTP_RESPONSE(413, "Request Entity Too Large"));
	http_responses.insert(HTTP_RESPONSE(414, "Request-URI Too Long"));
	http_responses.insert(HTTP_RESPONSE(415, "Unsupported Media Type"));
	http_responses.insert(HTTP_RESPONSE(416, "Requested Range Not Satisfiable"));
	http_responses.insert(HTTP_RESPONSE(417, "Expectation Failed"));
	http_responses.insert(HTTP_RESPONSE(500, "Internal Server Error"));
	http_responses.insert(HTTP_RESPONSE(501, "Not Implemented"));
	http_responses.insert(HTTP_RESPONSE(502, "Bad Gateway"));
	http_responses.insert(HTTP_RESPONSE(503, "Service Unavailable"));
	http_responses.insert(HTTP_RESPONSE(504, "Gateway Timeout"));
	http_responses.insert(HTTP_RESPONSE(505, "HTTP Version Not Supported"));
}

ZMWSHTTPUtils::~ZMWSHTTPUtils(void){
	http_responses.clear();
}

const std::string ZMWSHTTPUtils::getReasonPhrase(const int http_ret_code) {

	if (http_responses.find(http_ret_code) != http_responses.end()) {
		return http_responses[http_ret_code];
	}
	return defaultHTTPResp;
}
