dmpserverrequest.cpp
2.5 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
/**************************************************************************
* file: dmpserverrequest.cpp
* Author: wanzhongping
* Date: 2021-01-08 11:10:59
* Email: zhongpingw@chinadci.com
* copyright: 广州城市信息研究所有限公司
***************************************************************************/
#include "dmpserverrequest.h"
#include <regex>
// #include <boost/regex.hpp>
// #include <boost/make_shared.hpp>
// #include <boost/lexical_cast.hpp>
// #include <boost/algorithm/string.hpp>
#include "dmplogger.h"
DmpServerRequest::DmpServerRequest()
{
isRestful_ = false;
}
DmpServerRequest::DmpServerRequest(const std::string &url, Method method, const Headers &headers)
:url_(url)
,method_(method)
,headers_(headers)
{
isRestful_ = false;
}
void DmpServerRequest::setUrl(const std::string &url)
{
url_ = url;
if (!parseUrl(url_,protocol_,domain_,port_,path_,query_)) {
LOGGER_ERROR("非法的URL!");
return;
}
setQuery(query_);
}
void DmpServerRequest::setQuery(const std::string &queryString)
{
query_ = queryString;
if(!isRestful()) {
params_.setQueryString(query_);
}
}
void DmpServerRequest::setMethod(Method method)
{
method_ = method;
}
void DmpServerRequest::setParameter(const std::string &name, const std::string &value)
{
params_.add(name, value);
}
bool DmpServerRequest::parseUrl(const std::string& url,
std::string &protocol,
std::string &domain,
std::string &port,
std::string &path,
std::string &queryString)
{
if (url.empty()) {
return false;
}
std::regex reg("(http|https)://([^/ :]+):?([^/ ]*)(/?[^ #?]*)\\x3f?([^ #]*)#?([^ ]*)");
std::cmatch what;
if (std::regex_match(url.c_str(), what, reg))
{
protocol = what[1].str();
domain = what[2].str();
port = what[3].str();
path = what[4].str();
queryString = what[5].str();
return true;
}
return false;
}
void DmpServerRequest::setHeader(const std::string &name, const std::string &value)
{
headers_[name] = value;
}
const void* DmpServerRequest::GetData() const
{
return nullptr;
}
int DmpServerRequest::GetDataLength() const
{
return 0;
}