summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Tanous <ed.tanous@intel.com>2019-09-03 10:11:01 -0700
committerEd Tanous <ed.tanous@intel.com>2019-09-16 22:29:42 +0000
commit6295becabb9edba2edb53a3c0dddc13d2ffac8dd (patch)
tree3234a6455c3ec1ccab2cf84730e2bfc8c4bb775c
parente3e2961881040e7632bd139dcf722c2afa8408f1 (diff)
downloadbmcweb-6295becabb9edba2edb53a3c0dddc13d2ffac8dd.tar.gz
bmcweb-6295becabb9edba2edb53a3c0dddc13d2ffac8dd.zip
Don't throw if no-content is provided
In a perfect world, we would implement all no-content cases correctly, and never set a no-content return code, then provide content. In practice, in an async context, this is difficult to manage, as has been proven a couple times to be beyond what we're able to review. This error should be made less fatal, and still return a response to the user, rather than throwing and closing the connection entirely. This patchset implements a corrective action where the content is dropped in the connection if the handler sets the no-content code. Tested: Still need to test. In theory, not possible without a unit test for a buggy handler. Signed-off-by: Ed Tanous <ed.tanous@intel.com> Change-Id: Ie6fea0c3fef107578b855b7c43a634d51b2064de
-rw-r--r--crow/include/crow/http_connection.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/crow/include/crow/http_connection.h b/crow/include/crow/http_connection.h
index 6f44186..78ee70b 100644
--- a/crow/include/crow/http_connection.h
+++ b/crow/include/crow/http_connection.h
@@ -447,6 +447,17 @@ class Connection
{
res.body() = std::string(res.reason());
}
+
+ if (res.result() == boost::beast::http::status::no_content)
+ {
+ // Boost beast throws if content is provided on a no-content
+ // response. Ideally, this would never happen, but in the case that
+ // it does, we don't want to throw.
+ BMCWEB_LOG_CRITICAL
+ << "Response content provided but code was no-content";
+ res.body().clear();
+ }
+
res.addHeader(boost::beast::http::field::server, serverName);
res.addHeader(boost::beast::http::field::date, getCachedDateStr());
OpenPOWER on IntegriCloud