52 lines
902 B
C++
52 lines
902 B
C++
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
|
|
//SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <array>
|
|
#include <string_view>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include "stream/ostream.h"
|
|
|
|
class Request;
|
|
class Response {
|
|
friend class Request;
|
|
|
|
public:
|
|
enum class Status {
|
|
ok,
|
|
badRequest,
|
|
unauthorized,
|
|
notFound,
|
|
methodNotAllowed,
|
|
conflict,
|
|
internalError,
|
|
__size
|
|
};
|
|
|
|
enum class ContentType {
|
|
text,
|
|
json,
|
|
__size
|
|
};
|
|
|
|
uint16_t statusCode() const;
|
|
|
|
void send() const;
|
|
void setBody(const std::string& body);
|
|
void setBody(const nlohmann::json& body);
|
|
|
|
private:
|
|
Response(Request& request);
|
|
Response(Request& request, Status status);
|
|
|
|
private:
|
|
Request& request;
|
|
Status status;
|
|
ContentType type;
|
|
std::string body;
|
|
};
|