Add win socket client and server.
This commit is contained in:
parent
426ea55b3b
commit
4d2464c1f5
45 changed files with 1167 additions and 246 deletions
|
@ -1,14 +1,14 @@
|
|||
#include "HttpRequest.h"
|
||||
|
||||
#include "StringUtils.h"
|
||||
#include "HttpParser.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
HttpRequest::HttpRequest(Verb verb, const std::string& path)
|
||||
: mVerb(verb),
|
||||
mPath(path)
|
||||
: mVerb(verb)
|
||||
{
|
||||
|
||||
mPreamble.mPath = path;
|
||||
}
|
||||
|
||||
HttpRequest::Verb HttpRequest::getVerb() const
|
||||
|
@ -18,22 +18,38 @@ HttpRequest::Verb HttpRequest::getVerb() const
|
|||
|
||||
std::string HttpRequest::getPath() const
|
||||
{
|
||||
return mPath;
|
||||
return mPreamble.mPath;
|
||||
}
|
||||
|
||||
void HttpRequest::parseMessage(const std::string& message)
|
||||
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};
|
||||
bool firstLine{ true };
|
||||
|
||||
std::vector<std::string> headers;
|
||||
while(std::getline(ss, buffer, '\n'))
|
||||
while (std::getline(ss, buffer, '\n'))
|
||||
{
|
||||
if (firstLine)
|
||||
{
|
||||
parseFirstLine(buffer);
|
||||
HttpParser::parsePreamble(buffer, mPreamble);
|
||||
firstLine = false;
|
||||
}
|
||||
else
|
||||
|
@ -41,45 +57,16 @@ void HttpRequest::parseMessage(const std::string& message)
|
|||
headers.push_back(buffer);
|
||||
}
|
||||
}
|
||||
mHeader.parse(headers);
|
||||
}
|
||||
|
||||
void HttpRequest::parseFirstLine(const std::string& line)
|
||||
{
|
||||
bool inPath{false};
|
||||
bool inMethod{true};
|
||||
bool inProtocol{false};
|
||||
|
||||
for (std::size_t idx=0; idx<line.size();idx++)
|
||||
if (mPreamble.mMethod == "GET")
|
||||
{
|
||||
const auto c = line[idx];
|
||||
if (inPath)
|
||||
{
|
||||
if (StringUtils::isSpace(c))
|
||||
{
|
||||
inPath = false;
|
||||
inMethod = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mMethod.push_back(c);
|
||||
}
|
||||
}
|
||||
else if (inMethod)
|
||||
{
|
||||
if (StringUtils::isSpace(c))
|
||||
{
|
||||
inMethod = false;
|
||||
inProtocol = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mPath.push_back(c);
|
||||
}
|
||||
}
|
||||
else if (inProtocol)
|
||||
{
|
||||
mProtocolVersion.push_back(c);
|
||||
}
|
||||
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