#include "Header.h" #include "Log.h" namespace core { Header::Header(std::string data) : data(data) { // Log(LOG_DEBUG_4) << data; } Header::~Header() {} std::string Header::requestMethod() { return data.substr(0, data.find(" ")); } std::string Header::requestURL() { std::string temp = data.substr(data.find(" ") + 1); return temp.substr(0, temp.find(" ")); } std::string Header::requestProtocol() { std::string line1 = data.substr(0, data.find("\r\n")); return line1.substr(line1.rfind(" ") + 1); } std::string Header::getPath() { std::string temp = requestURL().substr(requestURL().find('/')); return temp.substr(0, temp.find('?')); } std::string Header::getCGIData() { return requestURL().substr(requestURL().find('?') + 1); } std::string Header::getCookie(std::string cookie) { // TODO: Should do a more solid processing of this format of data. int ix = 0; while(ix < data.length()) { if(data.substr(ix, 7) == "Cookie:") { ix += 7; // TODO: Check for space here. ix += 1; int len = data.find("=", ix) - ix; if(cookie == data.substr(ix, len)) { ix += len + 1; len = data.find("\r\n", ix) - ix; return data.substr(ix, len); } } ix += data.find("\r\n", ix) - ix + 2; } return ""; } }