first couple of requests
This commit is contained in:
parent
68e795f0e6
commit
aae7873d67
11 changed files with 152 additions and 34 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue