-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.hpp
More file actions
114 lines (86 loc) · 3.51 KB
/
http.hpp
File metadata and controls
114 lines (86 loc) · 3.51 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef HTTP_HPP
#define HTTP_HPP
#include <string>
#include <vector>
#include <map>
#include <nlohmann/json.hpp>
namespace http {
class URI {
public:
std::vector<std::string> route;
std::map<std::string, std::string> parameters;
URI();
URI(const std::string& uriString);
};
struct request {
std::string method;
URI uri;
std::string version = "HTTP/1.1";
std::map<std::string, std::string> headers;
std::string body;
};
struct response {
std::string version = "HTTP/1.1";
int status_code;
std::string status_message;
std::map<std::string, std::string> headers;
std::string body;
};
request parse_request(const std::string& input);
std::string serialize_response(response& res);
response ok();
response ok(const nlohmann::json& body);
response ok(const std::string& content_type, const std::string& body);
response created();
response created(const nlohmann::json& body);
response created(const std::string& content_type, const std::string& body);
response accepted();
response accepted(const nlohmann::json& body);
response accepted(const std::string& content_type, const std::string& body);
response no_content();
response moved_permanently(const std::string& location);
response found(const std::string& location);
response not_modified();
response temporary_redirect(const std::string& location);
response permanent_redirect(const std::string& location);
response bad_request();
response bad_request(const nlohmann::json& body);
response bad_request(const std::string& content_type, const std::string& body);
response unauthorized();
response unauthorized(const nlohmann::json& body);
response unauthorized(const std::string& content_type, const std::string& body);
response forbidden();
response forbidden(const nlohmann::json& body);
response forbidden(const std::string& content_type, const std::string& body);
response not_found();
response not_found(const nlohmann::json& body);
response not_found(const std::string& content_type, const std::string& body);
response method_not_allowed();
response method_not_allowed(const nlohmann::json& body);
response method_not_allowed(const std::string& content_type, const std::string& body);
response conflict();
response conflict(const nlohmann::json& body);
response conflict(const std::string& content_type, const std::string& body);
response unprocessable_entity();
response unprocessable_entity(const nlohmann::json& body);
response unprocessable_entity(const std::string& content_type, const std::string& body);
response too_many_requests();
response too_many_requests(const nlohmann::json& body);
response too_many_requests(const std::string& content_type, const std::string& body);
response internal_server_error();
response internal_server_error(const nlohmann::json& body);
response internal_server_error(const std::string& content_type, const std::string& body);
response not_implemented();
response not_implemented(const nlohmann::json& body);
response not_implemented(const std::string& content_type, const std::string& body);
response bad_gateway();
response bad_gateway(const nlohmann::json& body);
response bad_gateway(const std::string& content_type, const std::string& body);
response service_unavailable();
response service_unavailable(const nlohmann::json& body);
response service_unavailable(const std::string& content_type, const std::string& body);
response gateway_timeout();
response gateway_timeout(const nlohmann::json& body);
response gateway_timeout(const std::string& content_type, const std::string& body);
}
#endif // HTTP_HPP