#include "HttpHeader.h" #include "Char.h" HttpHeader::HttpHeader() : mHttpVersion("1.1"), mContentType("text / html") { } String HttpHeader::getContentType() const { return mContentType; } String HttpHeader::getHttpVersion() const { return mHttpVersion; } void HttpHeader::parse(const Vector& message) { String tag; String value; bool foundDelimiter{false}; for (const auto& line : message) { for(size_t idx = 0; idx< line.size(); idx++) { const auto c = line[idx]; if (c == Char::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.insert(tag, value); } }