-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttp_response.h
More file actions
66 lines (51 loc) · 1.53 KB
/
Copy pathhttp_response.h
File metadata and controls
66 lines (51 loc) · 1.53 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
#pragma once
#include <netpoll/util/message_buffer.h>
#include <netpoll/util/string_view.h>
#include <string>
#include <unordered_map>
#include "types.h"
namespace http {
struct fileinfo
{
unsigned long long filesize{};
std::string filename;
};
class Response
{
public:
auto version() -> Version& { return version_; }
auto statusCode() -> StatusCode& { return statusCode_; }
auto connectionState() -> ConnectionState& { return connectionState_; }
void responseBad()
{
statusCode_ = StatusCode::k400BadRequest;
connectionState_ = ConnectionState::kClose;
}
void responseOk()
{
statusCode_ = StatusCode::k200Ok;
connectionState_ = ConnectionState::kClose;
}
auto statusMsg() -> std::string& { return statusMsg_; }
auto body() -> std::string& { return body_; }
auto headers() -> std::unordered_map<std::string, std::string>&
{
return headers_;
}
auto fileinfo() -> fileinfo& { return fileinfo_; }
bool hasFile() const { return fileinfo_.filesize != 0; }
void setContentType(netpoll::StringView const& type)
{
headers_["Content-Type"] = {type.data(), type.size()};
}
std::string toString();
private:
Version version_{Version::kHttp11};
StatusCode statusCode_{StatusCode::kUnknown};
ConnectionState connectionState_{ConnectionState::kKeepAlive};
std::string statusMsg_;
struct fileinfo fileinfo_;
std::string body_;
std::unordered_map<std::string, std::string> headers_;
};
} // namespace http