Set the response Access-Control-Allow-Headers header correctly for OPTIONS requests (#534)

This commit is contained in:
An Tao 2020-08-13 21:41:29 +08:00 committed by GitHub
parent 857cacfda7
commit 3a10db99c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 6 deletions

View File

@ -660,8 +660,11 @@ void HttpControllersRouter::doPreHandlingAdvices(
resp->addHeader("Access-Control-Allow-Origin", origin);
}
resp->addHeader("Access-Control-Allow-Methods", methods);
resp->addHeader("Access-Control-Allow-Headers",
"x-requested-with,content-type");
auto &headers = req->getHeaderBy("access-control-request-headers");
if (!headers.empty())
{
resp->addHeader("Access-Control-Allow-Headers", headers);
}
callback(resp);
return;
}

View File

@ -337,8 +337,11 @@ void HttpSimpleControllersRouter::doPreHandlingAdvices(
resp->addHeader("Access-Control-Allow-Origin", origin);
}
resp->addHeader("Access-Control-Allow-Methods", methods);
resp->addHeader("Access-Control-Allow-Headers",
"x-requested-with,content-type");
auto &headers = req->getHeaderBy("access-control-request-headers");
if (!headers.empty())
{
resp->addHeader("Access-Control-Allow-Headers", headers);
}
callback(resp);
return;
}

View File

@ -282,8 +282,11 @@ void WebsocketControllersRouter::doControllerHandler(
resp->addHeader("Access-Control-Allow-Origin", origin);
}
resp->addHeader("Access-Control-Allow-Methods", methods);
resp->addHeader("Access-Control-Allow-Headers",
"x-requested-with,content-type");
auto &headers = req->getHeaderBy("access-control-request-headers");
if (!headers.empty())
{
resp->addHeader("Access-Control-Allow-Headers", headers);
}
callback(resp);
return;
}