-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathResponse.h
More file actions
101 lines (80 loc) · 1.93 KB
/
Response.h
File metadata and controls
101 lines (80 loc) · 1.93 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
//
// Created by Alone on 2022-7-21.
//
#ifndef MYUTIL_RESPONSE_H
#define MYUTIL_RESPONSE_H
#include <string>
#include <string_view>
#include <optional>
#include "Request.h"
namespace http
{
using std::optional;
using std::string;
using std::string_view;
class Response
{
public:
using head_t = Request::head_t;
static optional<string> get_status_text(int status);
static optional<string> get_body_type_text(int type);
static int get_type_from_text(string const &text);
VERSION &version()
{
return m_httpVersion;
}
STATUS_CODE &status()
{
return m_status;
}
string &status_description()
{
return m_status_description;
}
head_t &head()
{
return m_head;
}
string &body()
{
return m_body;
}
long &content_length()
{
return m_contentLen;
}
Response &SetStatus(STATUS_CODE status)
{
m_status = status;
return *this;
}
Response &SetContentType(ACCEPT_CONTENT_TYPE contentType)
{
m_contentType = contentType;
return *this;
}
Response &SetConnection(bool status)
{
m_keep_alive = status;
return *this;
}
Response &SetContentLength(int length)
{
m_contentLen = length;
return *this;
}
void init_special_fields();
string to_string();
private:
VERSION m_httpVersion = VERSION1_1;
STATUS_CODE m_status = static_cast<STATUS_CODE>(0);
int m_contentType = -1;
long m_contentLen{};
bool m_keep_alive{};
string m_host;
string m_status_description;
string m_body;
head_t m_head;
};
}
#endif // MYUTIL_RESPONSE_H