正在显示
1 个修改的文件
包含
80 行增加
和
0 行删除
src/server/dmpserverrequest.cpp
0 → 100644
1 | + | |
2 | +/************************************************************************** | |
3 | + * file: dmpserverrequest.cpp | |
4 | + | |
5 | + * Author: wanzhongping | |
6 | + * Date: 2021-01-08 11:10:59 | |
7 | + * Email: zhongpingw@chinadci.com | |
8 | + * copyright: 广州城市信息研究所有限公司 | |
9 | + ***************************************************************************/ | |
10 | + | |
11 | +#include "dmpserverrequest.h" | |
12 | +#include <boost/regex.hpp> | |
13 | +#include <boost/make_shared.hpp> | |
14 | +#include "dmplogger.h" | |
15 | + | |
16 | +DmpServerRequest::DmpServerRequest() | |
17 | +{ | |
18 | +} | |
19 | + | |
20 | +DmpServerRequest::DmpServerRequest(const std::string &url, Method method, const Headers &headers) | |
21 | + :url_(url) | |
22 | + ,method_(method) | |
23 | + ,headers_(headers) | |
24 | +{ | |
25 | +} | |
26 | + | |
27 | +void DmpServerRequest::set_url(const std::string &url) | |
28 | +{ | |
29 | + url_ = url; | |
30 | + if (!ParseUrl(url_,protocol_,domain_,port_,path_,query_)) { | |
31 | + LOGGER_ERROR("非法的URL!"); | |
32 | + return; | |
33 | + } | |
34 | + set_query(query_); | |
35 | +} | |
36 | + | |
37 | +void DmpServerRequest::set_query(const std::string &query_string) | |
38 | +{ | |
39 | + query_ = query_string; | |
40 | + params_.SetQueryString(query_); | |
41 | +} | |
42 | + | |
43 | +void DmpServerRequest::set_method(Method method) | |
44 | +{ | |
45 | + method_ = method; | |
46 | +} | |
47 | + | |
48 | +void DmpServerRequest::SetParameter(const std::string &name, const std::string &value) | |
49 | +{ | |
50 | + params_.Add(name, value); | |
51 | +} | |
52 | + | |
53 | +bool DmpServerRequest::ParseUrl(const std::string& url, | |
54 | + std::string &protocol, | |
55 | + std::string &domain, | |
56 | + std::string &port, | |
57 | + std::string &path, | |
58 | + std::string &query_string) | |
59 | +{ | |
60 | + if (url.empty()) { | |
61 | + return false; | |
62 | + } | |
63 | + boost::regex ex("(http|https)://([^/ :]+):?([^/ ]*)(/?[^ #?]*)\\x3f?([^ #]*)#?([^ ]*)"); | |
64 | + boost::cmatch what; | |
65 | + if (regex_match(url.c_str(), what, ex)) | |
66 | + { | |
67 | + protocol = std::string(what[1].first, what[1].second); | |
68 | + domain = std::string(what[2].first, what[2].second); | |
69 | + port = std::string(what[3].first, what[3].second); | |
70 | + path = std::string(what[4].first, what[4].second); | |
71 | + query_string = std::string(what[5].first, what[5].second); | |
72 | + return true; | |
73 | + } | |
74 | + return false; | |
75 | +} | |
76 | + | |
77 | +void DmpServerRequest::set_header(const std::string &name, const std::string &value) | |
78 | +{ | |
79 | + headers_[name] = value; | |
80 | +} | |
\ No newline at end of file | ... | ... |
请
注册
或
登录
后发表评论