Clean up win32 server example.
This commit is contained in:
parent
5362b694e0
commit
2c825adc1d
23 changed files with 337 additions and 156 deletions
|
@ -14,6 +14,8 @@ list(APPEND core_HEADERS
|
|||
file_utilities/PathUtils.h
|
||||
StringUtils.h
|
||||
http/HttpResponse.h
|
||||
http/HttpHeader.h
|
||||
http/HttpRequest.h
|
||||
serializers/TomlReader.h
|
||||
)
|
||||
|
||||
|
|
|
@ -2,6 +2,23 @@
|
|||
#include "StringUtils.h"
|
||||
|
||||
|
||||
HttpHeader::HttpHeader()
|
||||
: mContentType("text / html"),
|
||||
mHttpVersion("1.1")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string HttpHeader::getContentType() const
|
||||
{
|
||||
return mContentType;
|
||||
}
|
||||
|
||||
std::string HttpHeader::getHttpVersion() const
|
||||
{
|
||||
return mHttpVersion;
|
||||
}
|
||||
|
||||
void HttpHeader::parse(const std::vector<std::string >& message)
|
||||
{
|
||||
std::string tag;
|
||||
|
|
|
@ -7,10 +7,16 @@
|
|||
class HttpHeader
|
||||
{
|
||||
public:
|
||||
HttpHeader();
|
||||
void parse(const std::vector<std::string >& message);
|
||||
|
||||
private:
|
||||
std::string getContentType() const;
|
||||
|
||||
std::string getHttpVersion() const;
|
||||
|
||||
private:
|
||||
std::string mHttpVersion;
|
||||
std::string mContentType;
|
||||
std::string mHost;
|
||||
std::string mUserAgent;
|
||||
std::string mAccept;
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
#include "HttpResponse.h"
|
||||
|
||||
HttpResponse::HttpResponse()
|
||||
: mHttpVersion("1.1"),
|
||||
mStatusCode(200),
|
||||
: mStatusCode(200),
|
||||
mResponseReason("OK"),
|
||||
mContentType("text/plain"),
|
||||
mBody()
|
||||
{
|
||||
|
||||
|
@ -15,6 +13,11 @@ HttpResponse::~HttpResponse()
|
|||
|
||||
}
|
||||
|
||||
const HttpHeader& HttpResponse::getHeader() const
|
||||
{
|
||||
return mHeader;
|
||||
}
|
||||
|
||||
unsigned short HttpResponse::getStatusCode() const
|
||||
{
|
||||
return mStatusCode;
|
||||
|
@ -37,13 +40,13 @@ unsigned HttpResponse::getBodyLength() const
|
|||
|
||||
std::string HttpResponse::getHeaderString() const
|
||||
{
|
||||
std::string header = "HTTP/" + mHttpVersion + " " + std::to_string(mStatusCode) + " " + mResponseReason + "\n";
|
||||
header += "Content-Type: " + mContentType + "\n";
|
||||
std::string header = "HTTP/" + mHeader.getHttpVersion() + " " + std::to_string(mStatusCode) + " " + mResponseReason + "\n";
|
||||
header += "Content-Type: " + mHeader.getContentType() + "\n";
|
||||
header += "Content-Length: " + std::to_string(getBodyLength()) + "\n";
|
||||
return header;
|
||||
}
|
||||
|
||||
std::string HttpResponse::getResponseReason() const
|
||||
const std::string& HttpResponse::getResponseReason() const
|
||||
{
|
||||
return mResponseReason;
|
||||
}
|
||||
|
@ -52,3 +55,13 @@ std::string HttpResponse::toString() const
|
|||
{
|
||||
return getHeaderString() + "\n\n" + mBody;
|
||||
}
|
||||
|
||||
void HttpResponse::setStatusCode(unsigned short code)
|
||||
{
|
||||
mStatusCode = code;
|
||||
}
|
||||
|
||||
void HttpResponse::setResponseReason(const std::string& reason)
|
||||
{
|
||||
mResponseReason = reason;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "HttpHeader.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class HttpResponse
|
||||
|
@ -9,25 +11,29 @@ public:
|
|||
|
||||
~HttpResponse();
|
||||
|
||||
void setBody(const std::string& body);
|
||||
|
||||
unsigned getBodyLength() const;
|
||||
|
||||
const std::string& getBody() const;
|
||||
|
||||
const HttpHeader& getHeader() const;
|
||||
|
||||
std::string getHeaderString() const;
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
unsigned short getStatusCode() const;
|
||||
|
||||
std::string getResponseReason() const;
|
||||
const std::string& getResponseReason() const;
|
||||
|
||||
void setStatusCode(unsigned short code);
|
||||
|
||||
void setResponseReason(const std::string& reason);
|
||||
|
||||
void setBody(const std::string& body);
|
||||
|
||||
private:
|
||||
HttpHeader mHeader;
|
||||
unsigned short mStatusCode{ 200 };
|
||||
std::string mResponseReason{ };
|
||||
|
||||
std::string mHttpVersion;
|
||||
std::string mContentType;
|
||||
std::string mBody;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue