Initial commit
This commit is contained in:
38
src/http/request.cpp
Normal file
38
src/http/request.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "request.hpp"
|
||||
#include <sstream>
|
||||
|
||||
namespace Http
|
||||
{
|
||||
template<class T>
|
||||
T ToEnum(std::string const & str, std::vector<std::string> const & enumStrings)
|
||||
{
|
||||
for(unsigned i = 0; i < enumStrings.size(); ++i)
|
||||
{
|
||||
if (str.compare(enumStrings[i]) == 0)
|
||||
{
|
||||
return static_cast<T>(i);
|
||||
}
|
||||
}
|
||||
|
||||
return static_cast<T>(-1);
|
||||
}
|
||||
|
||||
Http::Request Request::Deserialize(std::vector<char> const & bytes)
|
||||
{
|
||||
// TODO serialize more than just the start
|
||||
Http::Request request;
|
||||
|
||||
std::stringstream ss(std::string(bytes.begin(), bytes.end()));
|
||||
|
||||
std::string requestTypeString;
|
||||
ss >> requestTypeString;
|
||||
request.requestType = ToEnum<HttpRequest::Type>(requestTypeString, HttpRequest::typeStrings);
|
||||
|
||||
ss >> request.path;
|
||||
|
||||
std::string httpProtocolString;
|
||||
ss >> httpProtocolString;
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user