Wayland example window

This commit is contained in:
jmsgrogan 2022-05-18 08:42:44 +01:00
parent 160b746182
commit 26f54c4581
30 changed files with 825 additions and 22 deletions

View file

@ -0,0 +1,80 @@
#include "HttpHeader.h"
#include "StringUtils.h"
void HttpHeader::parse(const std::vector<std::string >& 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;
}
}

View file

@ -0,0 +1,26 @@
#pragma once
#include <string>
#include <vector>
#include <map>
class HttpHeader
{
public:
void parse(const std::vector<std::string >& message);
private:
std::string mHost;
std::string mUserAgent;
std::string mAccept;
std::string mAcceptLanguage;
std::string mAcceptEncoding;
std::string mConnection;
std::string mReferer;
std::string mSecFetchDest;
std::string mSecFetchMode;
std::string mSecFetchSite;
std::map<std::string, std::string> mOtherFields;
};

View file

@ -0,0 +1,68 @@
#include "HttpRequest.h"
#include "StringUtils.h"
#include <sstream>
void HttpRequest::parseMessage(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)
{
parseFirstLine(buffer);
firstLine = false;
}
else
{
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++)
{
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);
}
}
}

View file

@ -0,0 +1,22 @@
#pragma once
#include "HttpHeader.h"
#include <string>
class HttpRequest
{
public:
HttpRequest() = default;
void parseMessage(const std::string& message);
private:
void parseFirstLine(const std::string& line);
HttpHeader mHeader;
std::string mMethod;
std::string mPath;
std::string mProtocolVersion;
};

View file

@ -5,11 +5,6 @@
class HttpResponse
{
std::string mHttpVersion;
std::string mResponseCode;
std::string mContentType;
std::string mBody;
public:
HttpResponse();
@ -23,4 +18,10 @@ public:
std::string GetHeaderString() const;
std::string ToString() const;
private:
std::string mHttpVersion;
std::string mResponseCode;
std::string mContentType;
std::string mBody;
};