-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhttp_response.h
55 lines (43 loc) · 1.3 KB
/
http_response.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2022, Eugene Gershnik
// Copyright (c) 2003-2022 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// SPDX-License-Identifier: BSD-3-Clause
#ifndef HEADER_HTTP_RESPONSE_H_INCLUDED
#define HEADER_HTTP_RESPONSE_H_INCLUDED
#include "xml_wrapper.h"
class HttpResponse
{
public:
enum Status
{
Ok = 200,
Created = 201,
Accepted = 202,
NoContent = 204,
MultipleChoices = 300,
MovedPermanently = 301,
MovedTemporarily = 302,
NotModified = 304,
BadRequest = 400,
Unauthorized = 401,
Forbidden = 403,
NotFound = 404,
InternalServerError = 500,
NotImplemented = 501,
BadGateway = 502,
ServiceUnavailable = 503
};
public:
HttpResponse(Status status = InternalServerError) : m_status(status) {
}
static auto makeStockResponse(Status status) -> HttpResponse;
static auto makeReply(XmlCharBuffer && xml) -> HttpResponse;
void addHeader(const sys_string & name, const sys_string & value);
auto makeBuffers() const -> std::vector<asio::const_buffer>;
private:
auto contentLength() const -> size_t;
private:
Status m_status;
std::variant<sys_string, XmlCharBuffer, std::u8string_view> m_content;
std::vector<sys_string> m_headers;
};
#endif