#include "HttpHeader.h" #include "StringUtils.h" HttpHeader::HttpHeader() : mContentType("text / html"), mHttpVersion("1.1") { } std::string HttpHeader::getContentType() const { return mContentType; } std::string HttpHeader::getHttpVersion() const { return mHttpVersion; } void HttpHeader::parse(const std::vector& message) { std::string tag; std::string value; bool foundDelimiter{false}; for (const auto& line : message) { for(std::size_t idx = 0; idx< line.size(); idx++) { const auto c = line[idx]; if (c == StringUtils::COLON) { foundDelimiter = true; } else if(foundDelimiter) { value.push_back(c); } else { tag.push_back(c); } } } if (tag.empty() || value.empty()) { return; } if (tag == "Host") { mHost = value; } else if (tag == "User-Agent") { mUserAgent = value; } else if (tag == "Accept") { mAccept = value; } else if (tag == "Accept-Language") { mAcceptLanguage = value; } else if (tag == "Accept-Encoding") { mAcceptEncoding = value; } else if (tag == "Connection") { mConnection = value; } else if (tag == "Referer") { mReferer = value; } else if (tag == "Sec-Fetch-Dest") { mSecFetchDest = value; } else if (tag == "Sec-Fetch-Mode") { mSecFetchMode = value; } else if (tag == "Sec-Fetch-Site") { mSecFetchSite = value; } else { mOtherFields[tag] = value; } }