Skip to content

Commit 926b9ed

Browse files
committed
>
1 parent 8f428e4 commit 926b9ed

2 files changed

Lines changed: 25 additions & 23 deletions

File tree

src/config.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace hcpp
3838
spdlog::error("{} : {}", config_path, j.get_errors());
3939
throw std::runtime_error("解析config出错");
4040
}
41-
//BUG https://github.com/dayu521/lsf/issues/5
41+
// BUG https://github.com/dayu521/lsf/issues/5
4242
lsf::json_to_struct_ignore_absence(*res, cs_);
4343

4444
// 主机映射配置文件
@@ -112,33 +112,26 @@ namespace hcpp
112112
std::map<unsigned int, std::pair<std::regex, InterceptSet>> star_map;
113113
for (auto &&i : cs_.proxy_service_)
114114
{
115-
if (i.doh_)
116-
{
117-
hh->add_intercept(std::make_pair(i.host_, i));
118-
}
119-
if (i.mitm_)
115+
std::smatch mr;
116+
if (std::regex_match(i.host_, mr, r))
120117
{
121-
std::smatch mr;
122-
if (std::regex_match(i.host_, mr, r))
118+
auto nstar = mr.size();
119+
if (nstar > 2)
123120
{
124-
auto nstar = mr.size();
125-
if (nstar > 2)
126-
{
127-
nstar -= 2;
128-
}
129-
assert(nstar > 0);
130-
if (i.host_ == "*")
131-
{
132-
i.host_ = "*.";
133-
}
134-
auto s = std::regex_replace(i.host_, std::regex(R"(\*\.)"), R"(.+\.)");
135-
log::info("构造的正则: {} -> {}", i.host_, s);
136-
star_map.insert({nstar, std::make_pair(std::regex(std::move(s)), std::move(i))});
121+
nstar -= 2;
137122
}
138-
else
123+
assert(nstar > 0);
124+
if (i.host_ == "*")
139125
{
140-
hh->add_intercept(std::make_pair(i.host_, std::move(i)));
126+
i.host_ = "*.";
141127
}
128+
auto s = std::regex_replace(i.host_, std::regex(R"(\*\.)"), R"(.+\.)");
129+
log::info("构造的正则: {} -> {}", i.host_, s);
130+
star_map.insert({nstar, std::make_pair(std::regex(std::move(s)), std::move(i))});
131+
}
132+
else
133+
{
134+
hh->add_intercept(std::make_pair(i.host_, std::move(i)));
142135
}
143136
}
144137

src/hcpp-cfg.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
"sni_host_":"www.baidu.com", //假的主机名
2525
"close_sni_":false //默认就是false.设置为true时,优先级高于sni_host_
2626
},
27+
{
28+
"host_":"*.github.com",
29+
"svc_":"443", //端口或服务名.例如 http https
30+
"url_":"", //暂未使用
31+
"mitm_":false, //使用mimt代理
32+
"doh_":true,
33+
"sni_host_":"www.baidu.com", //假的主机名
34+
"close_sni_":false //默认就是false.设置为true时,优先级高于sni_host_
35+
},
2736
{
2837
"host_":"avatars.githubusercontent.com",
2938
"svc_":"443",

0 commit comments

Comments
 (0)