#include "Response.h" #include "Log.h" namespace core { Response::Response() {} Response::~Response() {} std::string Response::getResponse(Mode mode) { return getResponse("", mode); } std::string Response::getResponse(std::string content, Mode mode) { std::stringstream response; response << protocol << " " << code << " " << text << CRLF; for(std::map::iterator item = header.begin(); item != header.end(); ++item) response << item->first << ": " << item->second << CRLF; if(mimeType != "") response << "Content-Type: " << mimeType << CRLF; if(mode == LENGTH) response << "Content-Length: " << content.length() << CRLF; else response << "Transfer-Encoding: chunked" << CRLF; response << CRLF; response << content; Log(LOG_DEBUG_4) << response.str(); return response.str(); } void Response::setProtocol(std::string protocol) { this->protocol = protocol; } void Response::setCode(std::string code) { this->code = code; } void Response::setText(std::string text) { this->text = text; } void Response::setMimeType(std::string mimeType) { this->mimeType = mimeType; } void Response::addHeaderItem(std::string key, std::string value) { header.insert(std::pair(key, value)); } void Response::setCookie(std::string name, std::string value) { addHeaderItem("Set-Cookie", name + "=" + value + ";"); } }