修复跨域问题: #2548

This commit is contained in:
xia-chu 2023-06-17 09:15:50 +08:00
parent 72ba87c803
commit ccddb84a19

View File

@ -594,6 +594,13 @@ void HttpSession::sendResponse(int code,
headerOut.emplace("Date", dateStr()); headerOut.emplace("Date", dateStr());
headerOut.emplace("Server", kServerName); headerOut.emplace("Server", kServerName);
headerOut.emplace("Connection", bClose ? "close" : "keep-alive"); headerOut.emplace("Connection", bClose ? "close" : "keep-alive");
GET_CONFIG(bool, allow_cross_domains, Http::kAllowCrossDomains);
if (allow_cross_domains) {
headerOut.emplace("Access-Control-Allow-Origin", "*");
headerOut.emplace("Access-Control-Allow-Credentials", "true");
}
if (!bClose) { if (!bClose) {
string keepAliveString = "timeout="; string keepAliveString = "timeout=";
keepAliveString += to_string(keepAliveSec); keepAliveString += to_string(keepAliveSec);