diff --git a/src/net/http_interceptor.cpp b/src/net/http_interceptor.cpp index 3a47fa5..fe74946 100644 --- a/src/net/http_interceptor.cpp +++ b/src/net/http_interceptor.cpp @@ -13,7 +13,7 @@ network::http::interceptor::~interceptor() { } -size_t network::http::interceptor::add(const std::string& express, std::function callback) +size_t network::http::interceptor::add(const std::string& express, std::function 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"); diff --git a/src/net/http_response.cpp b/src/net/http_response.cpp index efd1c7f..67f9289 100644 --- a/src/net/http_response.cpp +++ b/src/net/http_response.cpp @@ -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"; + } + } }