Fix CORS for new HTTP PATCH method (#477)

* Fix CORS for new HTTP PATCH method, also fix HttpRequestImpl::appendToBuffer, to be able to send PATCH requests

* Fix simple_example_test to work with updated CORS
This commit is contained in:
itgenie98 2020-06-15 04:05:05 +02:00 committed by GitHub
parent fda6a443a8
commit 2607f35687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 2 deletions

View File

@ -437,7 +437,7 @@ void doTest(const HttpClientPtr &client,
// LOG_DEBUG << resp->getBody();
auto allow = resp->getHeader("allow");
if (resp->statusCode() == k200OK &&
allow == "GET,HEAD,POST,PUT,DELETE,OPTIONS")
allow == "GET,HEAD,POST,PUT,DELETE,OPTIONS,PATCH")
{
outputGood(req, isHttps);
}

View File

@ -739,7 +739,7 @@ void HttpAppFrameworkImpl::onAsyncRequest(
{
auto resp = HttpResponse::newHttpResponse();
resp->setContentTypeCode(ContentType::CT_TEXT_PLAIN);
resp->addHeader("ALLOW", "GET,HEAD,POST,PUT,DELETE,OPTIONS");
resp->addHeader("ALLOW", "GET,HEAD,POST,PUT,DELETE,OPTIONS,PATCH");
resp->setExpiredTime(0);
callback(resp);
return;

View File

@ -644,6 +644,10 @@ void HttpControllersRouter::doPreHandlingAdvices(
{
methods.append("DELETE,");
}
if (routerItem.binders_[Patch] && routerItem.binders_[Patch]->isCORS_)
{
methods.append("PATCH,");
}
methods.resize(methods.length() - 1);
resp->addHeader("ALLOW", methods);
auto &origin = req->getHeader("Origin");

View File

@ -177,6 +177,9 @@ void HttpRequestImpl::appendToBuffer(trantor::MsgBuffer *output) const
case Options:
output->append("OPTIONS ");
break;
case Patch:
output->append("PATCH ");
break;
default:
return;
}

View File

@ -320,6 +320,10 @@ void HttpSimpleControllersRouter::doPreHandlingAdvices(
{
methods.append("DELETE,");
}
if (routerItem.binders_[Patch] && routerItem.binders_[Patch]->isCORS_)
{
methods.append("PATCH,");
}
methods.resize(methods.length() - 1);
resp->addHeader("ALLOW", methods);

View File

@ -265,6 +265,10 @@ void WebsocketControllersRouter::doControllerHandler(
{
methods.append("DELETE,");
}
if (routerItem.binders_[Patch] && routerItem.binders_[Patch]->isCORS_)
{
methods.append("PATCH,");
}
methods.resize(methods.length() - 1);
resp->addHeader("ALLOW", methods);