stuff-from-scratch/src/base/core/http/HttpParser.cpp
2023-01-27 17:04:39 +00:00

43 lines
No EOL
911 B
C++

#include "HttpParser.h"
#include "StringUtils.h"
bool HttpParser::parsePreamble(const std::string& line, HttpPreamble& preamble)
{
bool inPath{ false };
bool inMethod{ true };
bool inProtocol{ false };
for (const auto c : line)
{
if (inPath)
{
if (StringUtils::isSpace(c))
{
inPath = false;
inMethod = true;
}
else
{
preamble.mPath.push_back(c);
}
}
else if (inMethod)
{
if (StringUtils::isSpace(c))
{
inMethod = false;
inProtocol = true;
}
else
{
preamble.mMethod.push_back(c);
}
}
else if (inProtocol)
{
preamble.mVersion.push_back(c);
}
}
return true;
}