Start working on build system.
This commit is contained in:
parent
4b308f6c32
commit
521486be62
88 changed files with 1065 additions and 349 deletions
72
src/base/core/protocol/HttpRequest.cpp
Normal file
72
src/base/core/protocol/HttpRequest.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include "HttpRequest.h"
|
||||
|
||||
#include "StringUtils.h"
|
||||
#include "HttpParser.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
HttpRequest::HttpRequest(Verb verb, const std::string& path)
|
||||
: mVerb(verb)
|
||||
{
|
||||
mPreamble.mPath = path;
|
||||
}
|
||||
|
||||
HttpRequest::Verb HttpRequest::getVerb() const
|
||||
{
|
||||
return mVerb;
|
||||
}
|
||||
|
||||
std::string HttpRequest::getPath() const
|
||||
{
|
||||
return mPreamble.mPath;
|
||||
}
|
||||
|
||||
std::string HttpRequest::toString(const std::string& host) const
|
||||
{
|
||||
std::string out;
|
||||
|
||||
if (mVerb == Verb::GET)
|
||||
{
|
||||
out += "GET";
|
||||
}
|
||||
|
||||
auto path = mPreamble.mPath;
|
||||
out += " /" + path + " HTTP/" + mHeader.getHttpVersion() + "\n";
|
||||
out += "Host: " + host + "\n";
|
||||
out += "Accept - Encoding: \n";
|
||||
return out;
|
||||
}
|
||||
|
||||
void HttpRequest::fromString(const std::string& message)
|
||||
{
|
||||
std::stringstream ss(message);
|
||||
|
||||
std::string buffer;
|
||||
bool firstLine{ true };
|
||||
|
||||
std::vector<std::string> headers;
|
||||
while (std::getline(ss, buffer, '\n'))
|
||||
{
|
||||
if (firstLine)
|
||||
{
|
||||
HttpParser::parsePreamble(buffer, mPreamble);
|
||||
firstLine = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
headers.push_back(buffer);
|
||||
}
|
||||
}
|
||||
if (mPreamble.mMethod == "GET")
|
||||
{
|
||||
mVerb = Verb::GET;
|
||||
}
|
||||
mHeader.parse(headers);
|
||||
|
||||
mRequiredBytes = 0;
|
||||
}
|
||||
|
||||
std::size_t HttpRequest::requiredBytes() const
|
||||
{
|
||||
return mRequiredBytes;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue