增加SSL和普通双端口
This commit is contained in:
@@ -76,6 +76,7 @@ namespace ylib
|
||||
std::string domain;
|
||||
// 端口
|
||||
ushort port = 0;
|
||||
ushort port_ssl = 0;
|
||||
// 开启SSL
|
||||
bool ssl = false;
|
||||
};
|
||||
|
||||
@@ -20,5 +20,5 @@ If you have any questions, please contact us: 1585346868@qq.com Or visit our web
|
||||
namespace ylib
|
||||
{
|
||||
extern ylib::environment *env = new ylib::environment();
|
||||
extern ylib::log4* log = nullptr;
|
||||
extern ylib::log4* log = new ylib::log4("");
|
||||
}
|
||||
|
||||
@@ -171,6 +171,18 @@ std::vector<ushort> ylib::network::http::center::listen_ports()
|
||||
}
|
||||
if(find == false)
|
||||
ports.push_back(m_config.website[i].host[x].port);
|
||||
|
||||
find = false;
|
||||
for_iter(iter, ports)
|
||||
{
|
||||
if (*iter == m_config.website[i].host[x].port_ssl)
|
||||
{
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (find == false)
|
||||
ports.push_back(m_config.website[i].host[x].port_ssl);
|
||||
}
|
||||
}
|
||||
return ports;
|
||||
@@ -182,7 +194,7 @@ bool ylib::network::http::center::port_have_ssl(ushort port)
|
||||
{
|
||||
for (size_t x = 0; x < m_config.website[i].host.size(); x++)
|
||||
{
|
||||
if (m_config.website[i].host[x].port == port)
|
||||
if (m_config.website[i].host[x].port_ssl == port)
|
||||
{
|
||||
return m_config.website[i].host[x].ssl;
|
||||
}
|
||||
|
||||
@@ -154,24 +154,23 @@ bool ylib::network::http::response::send_file(const std::string& filepath, int32
|
||||
|
||||
//ylib::log->info(filepath2,"response");
|
||||
//取文件信息
|
||||
{
|
||||
struct stat statbuf;
|
||||
if (stat(filepath2.c_str(), &statbuf) != 0)
|
||||
return false;
|
||||
filesize = statbuf.st_size;
|
||||
last_modify_time = statbuf.st_mtime;
|
||||
}
|
||||
//{
|
||||
// auto filesize = std::filesystem::file_size(filepath2);
|
||||
// auto ftime = std::filesystem::last_write_time(filepath2);
|
||||
// // 把 file_time_type 转为 system_clock::time_point
|
||||
// auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
|
||||
// ftime - decltype(ftime)::clock::now() + std::chrono::system_clock::now()
|
||||
// );
|
||||
|
||||
// // 转为 time_t(UNIX 时间戳)
|
||||
// last_modify_time = std::chrono::system_clock::to_time_t(sctp);
|
||||
// struct stat statbuf;
|
||||
// if (stat(filepath2.c_str(), &statbuf) != 0)
|
||||
// return false;
|
||||
// filesize = statbuf.st_size;
|
||||
// last_modify_time = statbuf.st_mtime;
|
||||
//}
|
||||
{
|
||||
filesize = std::filesystem::file_size(filepath2);
|
||||
auto ftime = std::filesystem::last_write_time(filepath2);
|
||||
// 把 file_time_type 转为 system_clock::time_point
|
||||
auto sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
|
||||
ftime - decltype(ftime)::clock::now() + std::chrono::system_clock::now()
|
||||
);
|
||||
// 转为 time_t(UNIX 时间戳)
|
||||
last_modify_time = std::chrono::system_clock::to_time_t(sctp);
|
||||
}
|
||||
// 设置为已发送
|
||||
m_response = true;
|
||||
//if (filesize != 0)
|
||||
|
||||
@@ -71,6 +71,7 @@ bool ylib::network::http::website::start(const website_config& config)
|
||||
for (size_t i = 0; i < m_config.host.size(); i++)
|
||||
{
|
||||
auto hostpoint = new network::http::host;
|
||||
auto hostpoint_ssl = new network::http::host;
|
||||
|
||||
|
||||
network::http::ssl* ssl = nullptr;
|
||||
@@ -83,7 +84,7 @@ bool ylib::network::http::website::start(const website_config& config)
|
||||
ylib::log->warn("The certificate is not open or does not exist, Host:"+ m_config.host[i].domain);
|
||||
else
|
||||
{
|
||||
ssl = new network::http::ssl(center()->server(m_config.host[i].port),ssl_config);
|
||||
ssl = new network::http::ssl(center()->server(m_config.host[i].port_ssl),ssl_config);
|
||||
/*注册SSL*/
|
||||
if (ssl->regist() == false)
|
||||
{
|
||||
@@ -102,10 +103,25 @@ bool ylib::network::http::website::start(const website_config& config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
hostpoint->init(m_config.host[i].domain, m_config.host[i].port,ssl);
|
||||
}
|
||||
if (m_config.host[i].ssl)
|
||||
{
|
||||
hostpoint_ssl->init(m_config.host[i].domain, m_config.host[i].port_ssl, ssl);
|
||||
m_hosts.push_back(hostpoint_ssl);
|
||||
}
|
||||
hostpoint->init(m_config.host[i].domain, m_config.host[i].port,nullptr);
|
||||
m_hosts.push_back(hostpoint);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
if(m_cache->start(m_config.cache) == false)
|
||||
{
|
||||
|
||||
@@ -216,6 +216,8 @@ std::streamsize ylib::file_io::size()
|
||||
|
||||
bool file_io::is_open()
|
||||
{
|
||||
if (m_stream == nullptr)
|
||||
return false;
|
||||
return m_stream->is_open();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user