-
Notifications
You must be signed in to change notification settings - Fork 253
Expand file tree
/
Copy pathhttp_response.h
More file actions
60 lines (47 loc) · 1.43 KB
/
http_response.h
File metadata and controls
60 lines (47 loc) · 1.43 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
#ifndef TEST_HTTP_HTTP_RESPONSE_HEADER
#define TEST_HTTP_HTTP_RESPONSE_HEADER
#include <map>
#include <string>
enum HttpStatusCode {
kUnknown,
k200Ok = 200,
k301MovedPermanently = 301,
k400BadRequest = 400,
k404NotFound = 404,
};
class HttpResponse {
public:
explicit HttpResponse(bool close) : _status_code(kUnknown), _close_connection(close) {
}
void SetStatusCode(HttpStatusCode code) {
_status_code = code;
}
void SetStatusMessage(const std::string& message) {
_status_message = message;
}
void SetCloseConnection(bool on) {
_close_connection = on;
}
bool GetCloseConnection() const {
return _close_connection;
}
void SetContentType(const std::string& contentType) {
AddHeader("Content-Type", contentType);
}
// FIXME: replace string with StringPiece
void AddHeader(const std::string& key, const std::string& value) {
_headers_map[key] = value;
}
void SetBody(const std::string& body) {
_body = body;
}
std::string GetSendBuffer() const;
private:
std::map<std::string, std::string> _headers_map;
HttpStatusCode _status_code;
// FIXME: add http version
std::string _status_message;
bool _close_connection;
std::string _body;
};
#endif