Trace URI when body on 204/304
Trace URI on the existing CRITICAL message when a body exists but HTTP
return code was Informational responses (100 – 199), no-content (204),
or not_modified (304).
Tested: With these changes, the URI is traced on the CRITICAL message:
```
curl --http2 -k -H "Content-Type: application/json" \
-d '{"PowerRestorePolicy":"LastState"}' \
-X PATCH https://${bmc}/redfish/v1/Systems/system
root@p10bmc:~# journalctl | grep Response
Jun 20 15:30:46 p10bmc bmcwebd[296]: [http_response.hpp:213]
0x1353670 Response content provided but code was no-content
or not_modified, which aren't allowed to
have a body for url : "/redfish/v1/Systems/system"
```
Change-Id: I1ef618600642d355fc9f935d055b011e044caf5c
Signed-off-by: Abiola Asojo <abiola.asojo@ibm.com>
diff --git a/http/http_response.hpp b/http/http_response.hpp
index 46155a3..706bfb1 100644
--- a/http/http_response.hpp
+++ b/http/http_response.hpp
@@ -13,6 +13,7 @@
#include <boost/beast/http/fields.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/beast/http/status.hpp>
+#include <boost/url/url_view.hpp>
#include <nlohmann/json.hpp>
#include <cstddef>
@@ -186,10 +187,8 @@
return response.body().payloadSize();
}
- void preparePayload()
+ void preparePayload(const boost::urls::url_view& urlView)
{
- // This code is a throw-free equivalent to
- // beast::http::message::prepare_payload
std::optional<uint64_t> pSize = response.body().payloadSize();
using http::status;
@@ -209,8 +208,8 @@
{
BMCWEB_LOG_CRITICAL("{} Response content provided but code was "
"no-content or not_modified, which aren't "
- "allowed to have a body",
- logPtr(this));
+ "allowed to have a body for url : \"{}\"",
+ logPtr(this), urlView.path());
response.content_length(0);
return;
}