summaryrefslogtreecommitdiff
path: root/http/http_connection.hpp
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2023-06-23 00:06:22 +0300
committerEd Tanous <ed@tanous.net>2023-06-24 00:28:20 +0300
commited5f8954ff1dbfd68946122a37599106fb27c15d (patch)
tree36f1d89a25bf51d76a0fbddcf5d74294e8f60ec4 /http/http_connection.hpp
parent8d69c668d9be662447656869ce12c84b57ce4918 (diff)
downloadbmcweb-ed5f8954ff1dbfd68946122a37599106fb27c15d.tar.xz
Break out request completion from connection
There's a large part of the http::Connection class that has nothing to do with the connection at all, and is all about parsing, and finalizing the response. Break that portion out into its own method that can (in the future) be unit tested. Tested: Redfish service validator passes Change-Id: Ic608d432e69e25c0e0a1555ecc24ed62adba2664 Signed-off-by: Ed Tanous <edtanous@google.com>
Diffstat (limited to 'http/http_connection.hpp')
-rw-r--r--http/http_connection.hpp57
1 files changed, 2 insertions, 55 deletions
diff --git a/http/http_connection.hpp b/http/http_connection.hpp
index 11964e0c36..3548870418 100644
--- a/http/http_connection.hpp
+++ b/http/http_connection.hpp
@@ -3,12 +3,11 @@
#include "async_resp.hpp"
#include "authentication.hpp"
+#include "complete_response_fields.hpp"
#include "http_response.hpp"
#include "http_utility.hpp"
-#include "json_html_serializer.hpp"
#include "logging.hpp"
#include "mutual_tls.hpp"
-#include "security_headers.hpp"
#include "ssl_key_handler.hpp"
#include "utility.hpp"
@@ -314,66 +313,14 @@ class Connection :
res = std::move(thisRes);
res.keepAlive(keepAlive);
- BMCWEB_LOG_INFO << "Response: " << this << ' '
- << req->url().encoded_path() << ' ' << res.resultInt()
- << " keepalive=" << keepAlive;
-
- addSecurityHeaders(*req, res);
-
- crow::authentication::cleanupTempSession(*req);
+ completeResponseFields(*req, res);
if (!isAlive())
{
- // BMCWEB_LOG_DEBUG << this << " delete (socket is closed) " <<
- // isReading
- // << ' ' << isWriting;
- // delete this;
-
- // delete lambda with self shared_ptr
- // to enable connection destruction
res.setCompleteRequestHandler(nullptr);
return;
}
- res.setHashAndHandleNotModified();
-
- if (res.body().empty() && res.jsonValue.is_structured())
- {
- using http_helpers::ContentType;
- std::array<ContentType, 3> allowed{
- ContentType::CBOR, ContentType::JSON, ContentType::HTML};
- ContentType prefered =
- getPreferedContentType(req->getHeaderValue("Accept"), allowed);
-
- if (prefered == ContentType::HTML)
- {
- json_html_util::prettyPrintJson(res);
- }
- else if (prefered == ContentType::CBOR)
- {
- res.addHeader(boost::beast::http::field::content_type,
- "application/cbor");
- nlohmann::json::to_cbor(res.jsonValue, res.body());
- }
- else
- {
- // Technically prefered could also be NoMatch here, but we'd
- // like to default to something rather than return 400 for
- // backward compatibility.
- res.addHeader(boost::beast::http::field::content_type,
- "application/json");
- res.body() = res.jsonValue.dump(
- 2, ' ', true, nlohmann::json::error_handler_t::replace);
- }
- }
-
- if (res.resultInt() >= 400 && res.body().empty())
- {
- res.body() = std::string(res.reason());
- }
-
- res.addHeader(boost::beast::http::field::date, getCachedDateStr());
-
doWrite(res);
// delete lambda with self shared_ptr