优化HTTP模块
This commit is contained in:
@@ -13,7 +13,7 @@ network::http::interceptor::~interceptor()
|
||||
{
|
||||
|
||||
}
|
||||
size_t network::http::interceptor::add(const std::string& express, std::function<bool(network::http::reqpack* rp)> callback)
|
||||
size_t network::http::interceptor::add(const std::string& express, std::function<bool(network::http::reqpack* rp,const std::string&)> callback)
|
||||
{
|
||||
network::http::interceptor_info *info = new network::http::interceptor_info;
|
||||
info->express = std::regex(express.c_str());
|
||||
@@ -29,7 +29,7 @@ bool network::http::interceptor::trigger(const std::string& url, network::http::
|
||||
{
|
||||
auto info = m_array.get(i);
|
||||
if(std::regex_match(url.c_str(),info->express)){
|
||||
bool result = info->callback(rp);
|
||||
bool result = info->callback(rp,info->express_string);
|
||||
if(result == false){
|
||||
#if HTTP_INTERCEPTOR_PRINT == 1
|
||||
ylib::log->warn("["+rp->exec_msec()+" ms] false url:"+url+"\t"+" express:"+info->express_string+" ip:"+rp->request()->remote_ipaddress(true),"interceptor");
|
||||
|
||||
@@ -74,6 +74,18 @@ bool ylib::network::http::response::send(const char* buf, size_t buf_len, ushort
|
||||
{
|
||||
HEADER_SET("Content-Type", "text/html");
|
||||
HEADER_SET("Content-Length", std::to_string((uint64)view.length()));
|
||||
// 设置默认编码
|
||||
{
|
||||
std::string value;
|
||||
auto iter = m_headers.find("Content-Type");
|
||||
if (iter == m_headers.end() && iter->second.empty())
|
||||
iter->second = "charset=utf8";
|
||||
else
|
||||
{
|
||||
if (value.find("charset") == -1)
|
||||
iter->second += "; charset=utf8";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user