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:
parent
fda6a443a8
commit
2607f35687
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue