#include "response.hpp"
#include <sstream>

namespace Http
{
	std::vector<char> Response::Serialize() const
	{
		// TODO implement headers properly
		std::stringstream ss;
		ss << "HTTP/1.1";
		ss << ' ' << HttpResponse::codeValues[static_cast<int>(code)];
		ss << ' ' << HttpResponse::codeStrings[static_cast<int>(code)];
		ss << "\r\n";
		ss << "Server: http-server/0.1\r\n";
		
		if (contentType.size() > 0)
		{
			ss << "Content-Type: ";
			ss << contentType << "\r\n";
		}

		ss << "\r\n";
		
		auto header = ss.str();
		std::vector<char> buffer (header.begin(), header.end());
		buffer.insert(buffer.end(), content.begin(), content.end());

		return buffer;
	}

	Response::Response()
		: code(HttpResponse::Code::UNKNOWN),
		contentType(),
		content()
	{
	}
}