Initial quantum compute and cleaning up win server.
This commit is contained in:
parent
af50eea208
commit
5362b694e0
45 changed files with 884 additions and 429 deletions
12
src/core/AbstractWebApp.h
Normal file
12
src/core/AbstractWebApp.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "AbstractApp.h"
|
||||
|
||||
class HttpRequest;
|
||||
class HttpResponse;
|
||||
|
||||
class AbstractWebApp : public AbstractApp
|
||||
{
|
||||
public:
|
||||
virtual HttpResponse onHttpRequest(const HttpRequest& request) = 0;
|
||||
};
|
|
@ -2,6 +2,7 @@ set(MODULE_NAME core)
|
|||
|
||||
list(APPEND core_HEADERS
|
||||
AbstractApp.h
|
||||
AbstractWebApp.h
|
||||
Dictionary.h
|
||||
Event.h
|
||||
Color.h
|
||||
|
|
|
@ -4,6 +4,23 @@
|
|||
|
||||
#include <sstream>
|
||||
|
||||
HttpRequest::HttpRequest(Verb verb, const std::string& path)
|
||||
: mVerb(verb),
|
||||
mPath(path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
HttpRequest::Verb HttpRequest::getVerb() const
|
||||
{
|
||||
return mVerb;
|
||||
}
|
||||
|
||||
std::string HttpRequest::getPath() const
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
void HttpRequest::parseMessage(const std::string& message)
|
||||
{
|
||||
std::stringstream ss(message);
|
||||
|
|
|
@ -7,13 +7,31 @@
|
|||
class HttpRequest
|
||||
{
|
||||
public:
|
||||
|
||||
enum class Verb
|
||||
{
|
||||
GET,
|
||||
PUT,
|
||||
POST,
|
||||
PATCH,
|
||||
_DELETE,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
HttpRequest() = default;
|
||||
|
||||
HttpRequest(Verb verb, const std::string& path);
|
||||
|
||||
Verb getVerb() const;
|
||||
|
||||
std::string getPath() const;
|
||||
|
||||
void parseMessage(const std::string& message);
|
||||
|
||||
private:
|
||||
void parseFirstLine(const std::string& line);
|
||||
|
||||
Verb mVerb = Verb::UNKNOWN;
|
||||
HttpHeader mHeader;
|
||||
std::string mMethod;
|
||||
std::string mPath;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#include "HttpResponse.h"
|
||||
|
||||
HttpResponse::HttpResponse()
|
||||
:mHttpVersion("1.1"),
|
||||
mResponseCode("200 OK"),
|
||||
mContentType("text/plain"),
|
||||
mBody()
|
||||
: mHttpVersion("1.1"),
|
||||
mStatusCode(200),
|
||||
mResponseReason("OK"),
|
||||
mContentType("text/plain"),
|
||||
mBody()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -14,25 +15,40 @@ HttpResponse::~HttpResponse()
|
|||
|
||||
}
|
||||
|
||||
void HttpResponse::SetBody(const std::string& body)
|
||||
unsigned short HttpResponse::getStatusCode() const
|
||||
{
|
||||
return mStatusCode;
|
||||
}
|
||||
|
||||
const std::string& HttpResponse::getBody() const
|
||||
{
|
||||
return mBody;
|
||||
}
|
||||
|
||||
void HttpResponse::setBody(const std::string& body)
|
||||
{
|
||||
mBody = body;
|
||||
}
|
||||
|
||||
unsigned HttpResponse::GetBodyLength() const
|
||||
unsigned HttpResponse::getBodyLength() const
|
||||
{
|
||||
return unsigned(mBody.length());
|
||||
}
|
||||
|
||||
std::string HttpResponse::GetHeaderString() const
|
||||
std::string HttpResponse::getHeaderString() const
|
||||
{
|
||||
std::string header = "HTTP/" + mHttpVersion + " " + mResponseCode + "\n";
|
||||
std::string header = "HTTP/" + mHttpVersion + " " + std::to_string(mStatusCode) + " " + mResponseReason + "\n";
|
||||
header += "Content-Type: " + mContentType + "\n";
|
||||
header += "Content-Length: " + std::to_string(GetBodyLength()) + "\n";
|
||||
header += "Content-Length: " + std::to_string(getBodyLength()) + "\n";
|
||||
return header;
|
||||
}
|
||||
|
||||
std::string HttpResponse::ToString() const
|
||||
std::string HttpResponse::getResponseReason() const
|
||||
{
|
||||
return GetHeaderString() + "\n\n" + mBody;
|
||||
return mResponseReason;
|
||||
}
|
||||
|
||||
std::string HttpResponse::toString() const
|
||||
{
|
||||
return getHeaderString() + "\n\n" + mBody;
|
||||
}
|
||||
|
|
|
@ -9,17 +9,25 @@ public:
|
|||
|
||||
~HttpResponse();
|
||||
|
||||
void SetBody(const std::string& body);
|
||||
void setBody(const std::string& body);
|
||||
|
||||
unsigned GetBodyLength() const;
|
||||
unsigned getBodyLength() const;
|
||||
|
||||
std::string GetHeaderString() const;
|
||||
const std::string& getBody() const;
|
||||
|
||||
std::string ToString() const;
|
||||
std::string getHeaderString() const;
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
unsigned short getStatusCode() const;
|
||||
|
||||
std::string getResponseReason() const;
|
||||
|
||||
private:
|
||||
unsigned short mStatusCode{ 200 };
|
||||
std::string mResponseReason{ };
|
||||
|
||||
std::string mHttpVersion;
|
||||
std::string mResponseCode;
|
||||
std::string mContentType;
|
||||
std::string mBody;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue