1
0
forked from blue/pica
pica/response/response.h

53 lines
921 B
C
Raw Normal View History

2023-12-30 22:42:11 +00:00
//SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
//SPDX-License-Identifier: GPL-3.0-or-later
2023-11-21 22:19:08 +00:00
#pragma once
#include <string>
#include <array>
#include <string_view>
2023-11-23 19:57:32 +00:00
#include <nlohmann/json.hpp>
2023-11-21 22:19:08 +00:00
#include "stream/ostream.h"
2023-12-22 23:25:20 +00:00
class Request;
2023-11-21 22:19:08 +00:00
class Response {
2023-12-22 23:25:20 +00:00
friend class Request;
2023-11-21 22:19:08 +00:00
public:
enum class Status {
ok,
2023-12-22 23:25:20 +00:00
badRequest,
unauthorized,
2024-01-21 19:23:48 +00:00
forbidden,
2023-11-21 22:19:08 +00:00
notFound,
methodNotAllowed,
2023-12-22 23:25:20 +00:00
conflict,
2023-11-21 22:19:08 +00:00
internalError,
__size
};
enum class ContentType {
text,
2023-11-23 19:57:32 +00:00
json,
2023-11-21 22:19:08 +00:00
__size
};
2023-12-22 23:25:20 +00:00
uint16_t statusCode() const;
2023-11-21 22:19:08 +00:00
2023-12-13 20:33:11 +00:00
void send() const;
2023-11-21 22:19:08 +00:00
void setBody(const std::string& body);
2023-11-23 19:57:32 +00:00
void setBody(const nlohmann::json& body);
2023-11-21 22:19:08 +00:00
2023-12-22 23:25:20 +00:00
private:
Response(Request& request);
Response(Request& request, Status status);
2023-11-21 22:19:08 +00:00
private:
2023-12-13 20:33:11 +00:00
Request& request;
2023-11-21 22:19:08 +00:00
Status status;
ContentType type;
std::string body;
};