mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-12 12:25:21 +08:00
Merge pull request #168 from an-tao/dev
Add some necessary headers in preflight responses for CORS
This commit is contained in:
commit
06e4ed43b9
@ -221,10 +221,11 @@ int main()
|
||||
// return;
|
||||
accb();
|
||||
});
|
||||
app().registerPostHandlingAdvice(
|
||||
[](const drogon::HttpRequestPtr &, const drogon::HttpResponsePtr &) {
|
||||
LOG_DEBUG << "postHandling1";
|
||||
});
|
||||
app().registerPostHandlingAdvice([](const drogon::HttpRequestPtr &,
|
||||
const drogon::HttpResponsePtr &resp) {
|
||||
LOG_DEBUG << "postHandling1";
|
||||
resp->addHeader("Access-Control-Allow-Origin", "*");
|
||||
});
|
||||
app().registerPreRoutingAdvice([](const drogon::HttpRequestPtr &req) {
|
||||
LOG_DEBUG << "preRouting observer";
|
||||
});
|
||||
|
@ -174,8 +174,9 @@ class HttpRequest
|
||||
|
||||
/// Get the Json object of the request
|
||||
/**
|
||||
* The content type of the request must be 'application/json', otherwise
|
||||
* the method returns an empty object.
|
||||
* The content type of the request must be 'application/json', and the query
|
||||
* string (the part after the question mark in the URI) must be empty,
|
||||
* otherwise the method returns an empty shared_ptr object.
|
||||
*/
|
||||
virtual const std::shared_ptr<Json::Value> jsonObject() const = 0;
|
||||
const std::shared_ptr<Json::Value> getJsonObject() const
|
||||
|
@ -514,6 +514,10 @@ void HttpControllersRouter::doPreHandlingAdvices(
|
||||
}
|
||||
methods.resize(methods.length() - 1);
|
||||
resp->addHeader("ALLOW", methods);
|
||||
resp->addHeader("Access-Control-Allow-Origin", "*");
|
||||
resp->addHeader("Access-Control-Allow-Methods", methods);
|
||||
resp->addHeader("Access-Control-Allow-Headers",
|
||||
"x-requested-with,content-type");
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ void HttpRequestImpl::parseParameters() const
|
||||
std::transform(type.begin(), type.end(), type.begin(), tolower);
|
||||
if (_method == Get ||
|
||||
(_method == Post &&
|
||||
(type == "" ||
|
||||
(type.empty() ||
|
||||
type.find("application/x-www-form-urlencoded") != std::string::npos)))
|
||||
{
|
||||
std::string::size_type pos = 0;
|
||||
|
@ -379,6 +379,10 @@ void HttpSimpleControllersRouter::doPreHandlingAdvices(
|
||||
}
|
||||
methods.resize(methods.length() - 1);
|
||||
resp->addHeader("ALLOW", methods);
|
||||
resp->addHeader("Access-Control-Allow-Origin", "*");
|
||||
resp->addHeader("Access-Control-Allow-Methods", methods);
|
||||
resp->addHeader("Access-Control-Allow-Headers",
|
||||
"x-requested-with,content-type");
|
||||
callback(resp);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user