first couple of requests

This commit is contained in:
Blue 2023-11-23 16:57:32 -03:00
parent 68e795f0e6
commit aae7873d67
Signed by: blue
GPG key ID: 9B203B252A63EE38
11 changed files with 152 additions and 34 deletions

View file

@ -8,7 +8,8 @@ constexpr std::array<std::string_view, static_cast<uint8_t>(Response::Status::__
};
constexpr std::array<std::string_view, static_cast<uint8_t>(Response::ContentType::__size)> contentTypes = {
"Content-type: text/html"
"Content-type: text/plain",
"Content-type: application/json"
};
Response::Response():
@ -38,5 +39,11 @@ void Response::replyTo(Request& request) const {
}
void Response::setBody(const std::string& body) {
type = ContentType::text;
Response::body = body;
}
void Response::setBody(const nlohmann::json& body) {
type = ContentType::json;
Response::body = body.dump();
}

View file

@ -4,6 +4,8 @@
#include <array>
#include <string_view>
#include <nlohmann/json.hpp>
#include "request/request.h"
#include "stream/ostream.h"
@ -19,6 +21,7 @@ public:
enum class ContentType {
text,
json,
__size
};
Response();
@ -26,6 +29,7 @@ public:
void replyTo(Request& request) const;
void setBody(const std::string& body);
void setBody(const nlohmann::json& body);
private:
Status status;