-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathRequest.h
108 lines (85 loc) · 2.06 KB
/
Request.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
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
//
// Created by Alone on 2022-7-21.
//
#ifndef MYUTIL_REQUEST_H
#define MYUTIL_REQUEST_H
#include <map>
#include <string>
#include <vector>
#include <string_view>
#include "Url.h"
#include "PostForm.h"
namespace http
{
class PostForm;
using std::map;
using std::string;
using std::string_view;
using std::vector;
class Request
{
public:
using head_t = map<string, string>; //请求头的key-value对
using post_form_t = map<string, vector<string>>; // post请求的表单数据
VERSION &version()
{
return m_version;
}
METHOD &method()
{
return m_method;
}
string &url()
{
return m_url;
}
head_t &head()
{
return m_head;
}
string &body()
{
return m_body;
}
long &content_length()
{
return m_contentLen;
}
static METHOD get_method_from_text(string_view text);
void init_special_fields();
string to_string();
string Query(string const &key)
{
return m_urlData.Query(key);
}
vector<string> &QueryList(string const &key)
{
return m_urlData.From()[key];
}
// TODO
string PostQuery(string const &key)
{
return m_postForm.Query(key);
}
vector<string> &PostQueryList(string const &key)
{
return m_postForm.From()[key];
}
string PostMultiPart(string const &key)
{
}
private:
VERSION m_version = VERSION1_1;
METHOD m_method;
int m_contentType = -1;
long m_contentLen{};
bool m_keep_alive;
string m_host;
string m_url;
head_t m_head;
string m_body;
Url m_urlData; // url对应的数据(包含Query数据
PostForm m_postForm; // post对应的数据,主要是postForm的数据解析
};
}
#endif // MYUTIL_REQUEST_H